0

I'm trying to delete an email remotely using python's imap4 library and the email's uid value. I have tried using this code but it hasn't worked.

mail.store(uid,'+FLAGS','\\Deleted')
mail.expunge()

How do I delete this particular email?

McFizz
  • 3,013
  • 3
  • 18
  • 26
  • You might also want to consider IMAPClient (https://pypi.python.org/pypi/IMAPClient). It makes working with UIDs somewhat easier. – Menno Smits May 04 '17 at 12:20

1 Answers1

1

If you're using UIDs, you need to use UID store:

mail.uid('STORE', uid,'+FLAGS','\\Deleted')
mail.expunge()

Don't mix message sequence numbers (fetch, store, search) with UIDs (uid fetch, uid store, uid search). You might delete the wrong message all together!

Max
  • 10,701
  • 2
  • 24
  • 48