Postfix is a free and open-source MTA (mail transfer agent) used for email routing. When emails are sent, they are placed into a delivery queue and sent to the destination. On occasions where postfix cannot deliver/forward email, they will be placed into the deferred queue. This article outlines how to flush the queues - flushing will ask postfix to attempt to re-send emails struck in the queue.

Please note that you must be logged in as root to see the email queue and to run postfix commands.

How to purge, flush or delete the Postfix mail queue

First, to examine the contents of the queue

mailq

Next, to flush the postfix mail queue run

postfix flush

To retry all messages in the deferred queue

postsuper -r deferred

How to see email in Postfix queues

Use the postqueue command (or it’s alias mailq) to examine the Postfix queues

postqueue -p

OR

mailq

Either of these command will return output similar to this:

-Queue ID-  --Size-- ----Arrival Time---- -Sender/Recipient-------
24EB9888E       382 Thu Feb  6 16:31:33  root@fritz.box
(Host or domain name not found. Name service error for name=nowhere.com type=MX: Host not found, try again)
                                         someuser@nowhere.com

-- 0 Kbytes in 1 Request.

Take note of the Queue ID. In our example, 24EB9888E. With the Queue ID we can examine the message header, body and contents of the email as follows.

postcat -vq 24EB9888E

An example of the returned output follows:

postcat: name_mask: all
postcat: inet_addr_local: configured 2 IPv4 addresses
postcat: inet_addr_local: configured 3 IPv6 addresses
*** ENVELOPE RECORDS deferred/2/24EB9888E ***
message_size:             382             274               1               0             382               0
message_arrival_time: Thu Feb  6 16:31:33 2025
create_time: Thu Feb  6 16:31:33 2025
named_attribute: rewrite_context=local
sender_fullname: root
sender: root@fritz.box
named_attribute: dsn_orig_rcpt=rfc822;someuser@nowhere.com
original_recipient: someuser@nowhere.com
recipient: someuser@nowhere.com
*** MESSAGE CONTENTS deferred/2/24EB9888E ***
regular_text: Received: by mail.fritz.box (Postfix, from userid 0)
regular_text:   id 24EB9888E; Thu,  6 Feb 2025 16:31:33 +1100 (AEDT)
regular_text: Date: Thu, 6 Feb 2025 16:31:33 +1100
regular_text: From: root <root@fritz.box>
regular_text: To: someuser@nowhere.com
regular_text: Subject: Test
regular_text: Message-ID: <Z6RJNU-5HMaXbyGH@fritz.box>
regular_text: MIME-Version: 1.0
regular_text: Content-Type: text/plain; charset=us-ascii
regular_text: Content-Disposition: inline
regular_text: 
regular_text: This will not go anywhere !
*** HEADER EXTRACTED deferred/2/24EB9888E ***
*** MESSAGE FILE END deferred/2/24EB9888E ***

Deleting all emails from the Postfix queue

To remove all mail from the queue, enter:

postsuper -d ALL

To remove all mail in the deferred queue, enter:

postsuper -d ALL deferred

Summary

Here is a list of all commands needed to view and flush the Postfix mail queue:

Task Postfix command
View queued mail postqueue -p or mailq
Flush queued mail postqueue -f or postfix flush
Purge specific queued mail postsuper -d {ID}
Purge all mail from the queue postsuper -d ALL
Purge all mail from the deferred queue postsuper -d ALL deferred