Created
July 19, 2016 10:41
-
-
Save kholis/9a3df86ea064b081b4f02f46cf407219 to your computer and use it in GitHub Desktop.
Script to delete email by folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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