Postfix – How to Clear or Reset Queue

postfixubuntu-18.04

I recently discovered that one of our Ubuntu servers was generating dozens of notification emails a minute and throttling the Office 365 relay account it was sharing with a handful of other servers. I stopped the Postfix service on this server and disabled the scripts that were generating all of these alerts (and subsequent cascade of delivery failure messages). However, I didn't account for the Postfix Queue Manager which has retained thousands of these messages and attempts to send them all over again when I restart Postfix.

My first, admittedly bumbling, attempt to clear the queue was to navigate to the queue directory at /var/spool/postfix and manually remove files from the 'active' and 'incoming' folders. However, when I ran postqueue -p a ton of emails still showed up in the queue.

What is the best way to completely reset or purge a Postfix Queue?

Best Answer

You should use the postsuper command to delete messages from the Postfix queue - The -d <queueid> option would delete the message with the specified queue ID.

I'm using something like this script to run through all the messages in the mail queue:

mailq | awk '$7~/@/{print$1}' | while read qid; do postsuper -d $qid; done
Related Topic