Empty Postfix Mail Queue
This command will delete one specific email from the mailq (taken from the postsuper man page)
I use a few scripts that check the status of our servers and email/page me if they don’t respond. This led to a problem when I was offline for one reason or another. I would get a ton of messages sent to the postfix queue which would all be sent out when I reconnected to the internet. Deleting the postfix mail Queue is suprisingly easy:This command will delete all messages in the Postfix queue. If you need more selective deleting, this can be done as well, use ‘man postsuper’ to find out all of the available options.
The other thing that helped with this was checking for a local network connection before doing the server checks. This is done with the following.
To flush or purge the postfix mail queue, just enter this command
[crayon-5994bcfc5d5ba029489299 ]postfix -f
But if you need to delete an individual email from the queue, you’ll first need to see the queue. Traditionally you use
this time we’ll use:
[crayon-5994bcfc5d5c2411752579 ]postqueue -p
And the output should show all messages in queue:
[crayon-5994bcfc5d5c6231288464 ]5642B4D8647* 1683500 Tue Jun 3 08:37:27 firstname.lastname@example.org
9359B4D82B1* 1635730 Tue Jun 3 08:36:53 email@example.com
The first number is the message ID, if you only want to delete one of them, enter:
[crayon-5994bcfc5d5ca221330119 ]postsuper -d 5642B4D8647
That will only delete one email for the queue, that specific email you want to delete from it.
If you want to delete all deferred mails, you can use:
[crayon-5994bcfc5d5ce873224063 ]postsuper -d deferred