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-594d03d6c4082503095109 ]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-594d03d6c408c286644904 ]postqueue -p
And the output should show all messages in queue:
[crayon-594d03d6c4091855487073 ]5642B4D8647* 1683500 Tue Jun 3 08:37:27 email@example.com
9359B4D82B1* 1635730 Tue Jun 3 08:36:53 firstname.lastname@example.org
The first number is the message ID, if you only want to delete one of them, enter:
[crayon-594d03d6c4097424510320 ]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-594d03d6c409c615704684 ]postsuper -d deferred