0

Trail 1 :

 result, data = mail.uid("STORE", str(message_id), "+X-GM-LABELS", '"\\Trash"')

o/p :

BAD [b'Command Argument Error. 11']

Trail 2 :

result, data = mail.uid('STORE', str(message_id)  , '+FLAGS', '(\\Deleted)') 
print("Deleted the mail : " , result ,"-", details_log[4])
                
result, data = mail.uid('EXPUNGE', str(message_id))
print("result",result)
print("data",data)

o/p :

Deleted the mail :  OK
result NO
data [b'EXPUNGE failed.']

Issue : After Expunge , I even tried to close and logout the connection , but still it doesnt get deleted.

1 Answers1

0

I know this post is old, but for anyone who reads it later on:

When using imaplib's select function to choose a mailbox to view (in my case, the "Inbox" mailbox), I had the readonly argument set to True, to be safe, but this blocked me from deleting emails in Microsoft Outlook. I set it to False and was able to delete emails with the store and expunge methods:

conn.select("Inbox", readonly=False)

# modify search query as you see fit
typ, data = conn.search(None, "FROM", "scammer@whatever.com")

for email in data[0].split():
    conn.store(email, "+FLAGS", "\\Deleted")

conn.expunge()
conn.close()
conn.logout()

Dharman
  • 30,962
  • 25
  • 85
  • 135
David
  • 1