How to Flush the Postfix Mail Queue in Linux using the postqueue Command

Managing the Mail Spool

Postfix is one of the most widely used Mail Transfer Agents (MTAs) in the Linux ecosystem, commonly deployed on web servers to allow applications to send outgoing notification emails. When Postfix attempts to send an email, and the receiving server (like Gmail or Microsoft 365) temporarily rejects it (perhaps due to rate limiting or a temporary DNS failure), Postfix does not immediately drop the email. Instead, it places the email in a “deferred” queue and will attempt to resend it later.

If your server experiences a temporary internet outage, thousands of legitimate emails can pile up in this deferred queue. When the internet connection is restored, you do not want to wait for Postfix’s internal timer to slowly process the backlog. You need to manually flush the queue to force immediate delivery.

Step 1: Viewing the Queue

Before you flush the system, you should verify how many emails are actually stuck. To view a summary of the mail queue, open your terminal and use the mailq command (which is a symlink to the Postfix queue manager).

mailq

The output will show the Queue ID, the size, the arrival time, the sender, and the recipient for every stuck message. If the queue is massive, the final line of the output will provide a helpful summary, such as: -- 4 Kbytes in 12 Requests.

Step 2: Flushing the Queue

To force Postfix to immediately attempt redelivery of every single email currently sitting in the deferred queue, you must use the postqueue command with the -f (flush) flag.

Because you are interacting with core daemon services, you should execute this as root or via sudo:

sudo postqueue -f

The command executes silently and immediately returns you to the prompt. However, in the background, the Postfix master daemon is rapidly spinning up SMTP processes to blast the queued emails out to the internet.

You can verify it is working by running mailq again. You should see the number of requests rapidly decreasing.

Step 3: Deleting the Queue (The Nuclear Option)

Sometimes, the queue isn’t full of legitimate emails. If a PHP script on your web server was compromised by a hacker, it might have injected 50,000 spam emails into your Postfix queue. Flushing the queue in this scenario will result in your server being permanently blacklisted by global spam filters.

If the queue is full of spam, you must purge the queue entirely, deleting all messages without sending them.

To delete every single message from the queue, use the postsuper command with the -d ALL (delete all) flag:

sudo postsuper -d ALL

The terminal will output a confirmation, such as postsuper: Deleted: 50000 messages, instantly securing your server and protecting your IP reputation.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.