Postfix provides with postsuper, postqueue and mailq some  shell utilitys to manage the mailqueue.

Here are some examples for common tasks:

List all messages that are in the mailqueue

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 type=MX: Host not found, try again)
 [email protected]
-- 8 Kbytes in 1 Requests.

Delete a message by message ID

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

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 email address.

Remove emails by recipient

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 email address.

Remove emails by sender hostname

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

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

If your server has 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:

postsur -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. Message in the hold queue will not processed by postfix until they were requeued with postsuper -r.

Tagged on:

One thought on “Manage the postfix mailqueue with postsuper, postqueue and mailq

  • February 9, 2014 at 9:58 pm

    Nice work. Thank you


Leave a Reply

Your email address will not be published. Required fields are marked *