Manage the Postfix mail queue with postsuper, postqueue and mailq commands

Postfix provides several shell programs to manage the mail queue. These are:

  • postsuper
  • postqueue
  • mailq

In this tutorial, I will show you how to use these commands to manage the Postfix mail queue. Here are examples for common tasks:

List all messages that are in the mail queue

postqueue -p

The output looks like this:

[email protected]:/# postqueue -p
 -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
 501CA23B43DB     2182 Thu Dec  3 14:24:39  [email protected]
 (Host or domain name not found. Name service error for name=otherdomain.com type=MX: Host not found, try again)
 [email protected]
-- 8 Kbytes in 1 Requests.

Delete a message by message ID from Postfix mail queue

postsuper -d MessageID

replace MessageID with the ID of the message, e.g. 501CA23B43DB

[email protected]:/# postsuper -d 501CA23B43DB
 postsuper: 501CA23B43DB: removed
 postsuper: Deleted: 1 message

Remove emails by sender from Postfix mail queue

mailq | tail +2 | awk 'BEGIN { RS = "" }
 # $7=sender, $8=recipient1, $9=recipient2
 { if ($7 == "[email protected]" && $9 == "")
 print $1 }
 ' | tr -d '*!' | postsuper -d -

replace "[email protected]" with the sender's email address. In case you get a syntax error from the tail command, use this syntax:

mailq | tail -n +2 | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($7 == "[email protected]")
print $1 }
' | tr -d '*!' | postsuper -d -

Remove emails by recipient from Postfix mail queue

mailq | tail +2 | awk 'BEGIN { RS = "" }
 # $7=sender, $8=recipient1, $9=recipient2
 { if ($8 == "[email protected]" && $9 == "")
 print $1 }
 ' | tr -d '*!' | postsuper -d -

replace [email protected] with the recipient's email address.

In case you get a syntax error from the tail command, use this syntax:

mailq | tail -n +2 | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($8 == "[email protected]")
print $1 }
' | tr -d '*!' | postsuper -d -

Remove emails by sender hostname from Postfix mail queue

mailq | grep senderhostname | awk ‘{ print $1′} | postsuper -d -

replace the word "senderhostname" with the hostname of the email sender.

If your server has a very high load and you want to temporarily move all message from the incoming queue to the hold queue, use the command:

postsuper -h ALL

to move the messages back to the incoming queue, use the command:

postsuper -r ALL

Instead of the word "ALL" you can also provide a specific message ID to move only one message to or from the hold queue. Messages in the hold queue will not be processed by postfix until they were re-queued with "postsuper -r" command.

3 thoughts on “Manage the Postfix mail queue with postsuper, postqueue and mailq commands”

Leave a Comment

*