How to Flush the Mail Queue in Postfix | SendGrid

Postfix is a popular open-source mail transfer agent (MTA) that routes and delivers email. Occasionally, as part of the administration of this service, users will view, flush, and purge Postfix mail queues. These actions facilitate the manipulation of email delivery, enabling message reprioritization and/or cancellation. Such actions are often taken when messages are deferred or rejected from the recipient host.
View queued mail
In order to accomplish multiple queue operations such as flushing or purging, we must first see what email is in the queue. To accomplish this, we will use the postqueue -p command.
mailhost01:~ user01$ postqueue -p
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
75E95197CF2E* 315 Wed Jul 15 16:27:07 sender@test.com
recipient@test.com
87717197CE88* 315 Wed Jul 15 16:26:39 sender@test.com
recipient@test.com
In the above example, each queue entry shows the queue file ID, message size, arrival time, sender, and the recipients that still need to be delivered. The “*” or “!” characters at the end of the queue ID string represent the message’s queue status; active or hold.
Flush queued mail
To flush the mail queue, we will use the postqueue -f command. This command will attempt to redeliver all queued mail. Use the command sparingly, multiple flushes will impact the overall performance of your mail server.
mailhost01:~ user01$ postqueue -f
Purge queued mail
To purge the mail queue, we will use the postsuper -d command. This command has two execution options:
To purge a single email from the queue, use the postsuper -d [message id] command.
mailhost01:~ user01$ postqueue -p
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
75E95197CF2E* 315 Wed Jul 15 16:27:07 sender@test.com
recipient@test.com
87717197CE88* 315 Wed Jul 15 16:26:39 sender@test.com
recipient@test.com
mailhost01:~ user01$ sudo postsuper -d 75E95197CF2E
postsuper: 75E95197CF2E: removed
postsuper: Deleted: 1 message
To purge all email from the queue, use the postsuper -d ALL command.
mailhost01:~ user01$ postqueue -p
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
75E95197CF2E* 315 Wed Jul 15 16:27:07 sender@test.com
recipient@test.com
87717197CE88* 315 Wed Jul 15 16:26:39 sender@test.com
recipient@test.com
mailhost01:~ user01$ sudo postsuper -d ALL
postsuper: Deleted: 2 message
Conclusion
The need to manipulate mail queues is often the result of recipient hosts deferring or rejecting your messages. These deferrals or rejections will impact your overall email deliverability, which in return has a negative impact on your business communications. To read more about improving your email deliverability, review Twilio SendGrid’s annually published, Email Deliverability Guide.