Deleting a mail using IMAP

imap =‘IP’)
imap.login(‘username’, ‘password’)‘INBOX’)

if not imap.list(”, ‘TRASH’) #Create a TRASH Folder if it doesn’t exist

imap.copy(message_id, “TRASH”) #copy the message to the TRASH, “+FLAGS”, [:Deleted]) #Mark Deleted in INBOX

imap.expunge #Remove from INBOX

The above moves the mail to the TRASH….
To permanently delete, you can avoid copying the message to trash or mark it as deleted later and expunge!