Manage the postfix mailqueue with postsuper, postqueue und mailq

Friday, December 4, 2009 posted by Till

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:

root@server:/# postqueue -p -Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient------- 501CA23B43DB     2182 Thu Dec  3 14:24:39  test@yourdomain.com (Host or domain name not found. Name service error for name=otherdomain.com type=MX: Host not found, try again) info@otherdomain.com -- 8 Kbytes in 1 Requests. <strong>Delete a message by message ID</strong> <p class="command">postsuper -d MessageID

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

root@server:/# postsuper -d 501CA23B43DB postsuper: 501CA23B43DB: removed postsuper: Deleted: 1 message <strong>Remove emails by sender</strong> <p class="command">mailq | tail +2 | awk 'BEGIN { RS = "" } # $7=sender, $8=recipient1, $9=recipient2 { if ($7 == "info@otherdomain.com" &amp;&amp; $9 == "") print $1 } ' | tr -d '*!' | postsuper -d - replace "info@otherdomain.com" with the sender email address. <strong>Remove emails by recipient</strong> <p class="command">mailq | tail +2 | awk 'BEGIN { RS = "" } # $7=sender, $8=recipient1, $9=recipient2 { if ($8 == "you@yourdomain.com" &amp;&amp; $9 == "") print $1 } ' | tr -d '*!' | postsuper -d - replace you@yourdomain.com with the recipient email address. <strong>Remove emails by sender hostname</strong> <p class="command">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:

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

Share and Enjoy:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • FriendFeed
  • MisterWong
  • StumbleUpon


Leave a Reply