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 name=otherdomain.com 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. In case you get a syntax error from 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
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.
In case you get a syntax error from 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
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.
Nice work. Thank you
Typo in “to move the messages back to the incoming queue, use the command: postsur -r ALL”
Nice work. Thank you.
P.S.
You don’t need to use grep:
mailq | awk ‘/senderhostname/ { print $1}’ | postsuper -d –