Luke Cyca .com

IMAP Mass-delete

You know how when a meltdown happens and you get tens of thousands of automated emails telling you about it? And then cringes as you try to select them all and delete them? No? Then we do different work.

But if it ever does happen to you, you can use this python code snippit to connect directly to your mail server and delete them. I usually just paste this kind of thing right into the python interpreter.

The (FROM \"\") part is the selection criterion in this example, but there are more to choose from!

import imaplib
from getpass import getpass

imap = imaplib.IMAP4_SSL('')
typ, data =, '(FROM \"\")')
for num in data[0].split():, '+FLAGS', '\\Deleted')

Luke Cyca .com