Andrew Latham

Cleaning up a postfix mail queue is both dangerous and important when situations require it.

There will come a time when every admin needs to preform magic. This is some magic to remove emails from a Postfix queue when you have hundreds of thousands of emails and the mailq command can't finish.

mailq | awk 'BEGIN { RS = "" } /' | sed 's/!//' | postsuper -d -

In laymans terms, this script runs the mailq program and starts working on the output. This is both dangerous and fast. AWK jumps in and gets the mail ID and then SED will trim out the ! character if it is present, lastly the postsuper -d will delete what ever it gets. Change for whatever source of spam you are getting. If it is a country code you are having problems with you can do ".cc" for the TLD. Please use with caution.