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
postsupercommand, 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
mailqcommand, 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 email@example.com firstname.lastname@example.org email@example.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 firstname.lastname@example.org email@example.com firstname.lastname@example.org 9483E5CB40 851 Thu Jul 16 11:53:40 email@example.com 4483W5CB40 851 Thu Jul 16 11:53:40 firstname.lastname@example.org -- 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