I had some issue with one of mailserver, where postfix keeps retrying to send mail to a mistyped email address, it was very frustrating considering this particular email was holding back thousands of email, this how I solved it:
To delete a mail queue in Postfix, you use the postsuper
command, which is used for postfix mail queue related stuff, note that it can only be run by superuser of the system.
Before you delete a mail in the queue, you'll want to check if there is any mail in the queue at all, you can check by using the mailq
command, for example, I was trying to send a mail to multiple users, and let's assume it's not going through, you are gonna see something that looks similar as below:
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
7483D5CB40* 851 Thu Jul 16 11:53:40 user@gmail.com
user@gmail.com
user@yahoo.com
-- 0 Kbytes in 1 Request.
Note: The reason why I have multiple 'Sender/Recipient' above is that I am sending a single mail to multiple addresses, just the way you can add multiple emails when sending in an email client, e.g Gmail.
Now, to remove a mail queue, you note the -Queue ID-, and you then use the following command:
postsuper -d Mail_Queue_ID
Remove All Mails from Queue
This is where you would have multiple mails with different user, for illustration purpose, see below example:
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
7483D5CB40* 851 Thu Jul 16 11:53:40 user@gmail.com
user@gmail.com
user@yahoo.com
9483E5CB40 851 Thu Jul 16 11:53:40 anotheruser@gmail.com
4483W5CB40 851 Thu Jul 16 11:53:40 bob@gmail.com
-- 0 Kbytes in 1 Request.
You can see the above all have a different Queue ID, to clear them all, you use the following command:
postsuper -d ALL
Remove only All Deferred Mails In Queue
If you notice at the start of this guide I said, I had issue with some invalid recipient address, here is the deal:
The differed mail queue holds all messages or mails that have soft-failed (temporary failure), and need to be retried, in most case the failure can be due to invalid recipient address, or greylisting by spam filters.
If you want to delete only the differed mail queue, you use the following command:
postsuper -d ALL deferred
Enjoy.