Clearing the Postfix Queue

Clearing the Postfix Queue

Occasionally I do something stupid. I know, I'm a freakin' genius, but sometimes I goof.

Today was one of those days. I was importing a test batch of data containing about 30,000 pages into a new system. I realized after triggering the import that I had a bug in my code so I killed the process and then deleted the temp data.

What I didn't realize was that the data had already started the import process on the new machine. On the importing test machine it's configured to notify via email if something goes wrong. All of those notifications have a threshold that says if it goes over 10 warnings in one batch to kill the process entirely.

All notifications except one.

Net result: Over 25,000 email notifications.

So, here's how to properly clear a specific set of emails from a Postfix queue:

for i in `mailq|grep 'sender' |awk {'print $1'}|grep -v ''`; do postsuper -d $i ; done
Replace "sender" above with the first part of the email address of the sender, such as www-data, root, spambomber, whatever.
Posted by Tony on Apr 20, 2012 | Servers