The other day I recieved about 250,000 emails from a script I wrote.. I was in a hurry and didn’t properly log the output like I should of, or limit by quantity, or use any one of the 1000 better methods in my app. I simply sent out an email when it hit an error at a certain point to let me know.
import imaplib from getpass import getpass imap = imaplib.IMAP4_SSL('mail.example.com') imap.login('luke',getpass()) imap.select() typ, data = imap.search(None, '(FROM "firstname.lastname@example.org")') for num in data.split(): imap.store(num, '+FLAGS', '\Deleted') imap.expunge() imap.close() imap.logout()
This obviously filters by 'From' address, but you can easily filter by other stuff. Look here for more info.This took a while, but it was automatic and saved me a lot of time. Thought I'd pass it along.Like or share: