Skip to content

Instantly share code, notes, and snippets.

@kholis
Created July 19, 2016 10:41
Show Gist options
  • Save kholis/9a3df86ea064b081b4f02f46cf407219 to your computer and use it in GitHub Desktop.
Save kholis/9a3df86ea064b081b4f02f46cf407219 to your computer and use it in GitHub Desktop.
Script to delete email by folder
#!/usr/bin/env python
## http://stackoverflow.com/questions/3180891/imap-deleting-messages
import imaplib
m = imaplib.IMAP4_SSL('imap.company.com')
m.login("your-user","your-password")
m.select('mail/dir/sub-dir') # this folder will be clean up
typ, data = m.search(None, 'ALL')
for num in data[0].split():
#print num
m.store(num, '+FLAGS', '\\Deleted')
m.expunge()
m.close()
m.logout()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment