Home > centOS, Fedora 12 > Postfix cheat-sheet cheat code

Postfix cheat-sheet cheat code

General task:

How to check mail queue?

$postqueue -p

How to flash/resend the queue mails?

$postqueue -f

How to check the basic config?

$postconf -n

How to check whole config?

$postconf

How to make all queue as renew queue?

$postsuper -r ALL

How to reload the config after modification to my main.cf or master.cf?

$postfix reload
$service postfix restart

Problems

What to check for this error “relay=none, delay=0.02, delays=0.02/0.01/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to 127.0.0.1[127.0.0.1]: Connection refused)”

$check your master.cf if Dkim or Antivirus configurations are ok, if not ok or confused, comment it out and restart. In my case it was Dkim config error

Viewing the queue 
As I mention, sometimes mail gets stuck. Let’s see what’s inside the Postfix mail queue.

~# postqueue -p
-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
040481B31 3489 Tue Nov 22 00:02:33 MAILER-DAEMON
(connect to smtp2.greghorne.com[64.246.163.13]: Connection timed out)
fog@greghorne.com
E4C2E1C7B 3523 Tue Nov 22 00:02:34 MAILER-DAEMON
(connect to gfield.ednet.ns.ca[142.227.95.65]: Connection refused)
adevries@gfield.ednet.ns.ca

As you can see from this real-world example, there are two e-mails in the queue. Both of them are bounced messages, because the Sender is MAILER-DAEMON. You can see the error or why they ended in the queue (connect to smtp2.greghorne.com[64.246.163.13]: Connection timed out), and you can see the Queue ID of each message. You need that ID to operate on each one.

If there’s ‘*’ character next to queue ID
040481B31*
it means that this message is in the active queue e.g. attempts to deliver the messages are made.

If there’s ‘!’ character next to queue ID
040481B31!
it means that this message is put “on hold”.

Flushing the queue

The reasons to flush the queue may differ from tweaking your main.cf, or fixing some errors that your MDA reports, to resuming timed out connection. Here’s how to do it:
postqueue -f

Then check what’s going on in /var/log/mail.log:
{| WIDTH=”75%”
|-
|
~# tail -f /var/log/mail.log
Nov 22 00:28:22 mathilda postfix/qmgr[1990]: 040481B31: from=<>, size=3489, nrcpt=1 (queue active)
Nov 22 00:28:22 mathilda postfix/qmgr[1990]: E4C2E1C7B: from=<>, size=3523, nrcpt=1 (queue active)
Nov 22 00:28:22 mathilda postfix/smtp[9287]: connect to gfield.ednet.ns.ca[142.227.95.65]: Connection refused (port 25)
Nov 22 00:28:22 mathilda postfix/smtp[9287]: E4C2E1C7B: to=<adevries@gfield.ednet.ns.ca>, relay=none, delay=1548, status=deferred (connect to gfield.ednet.ns.ca[142.227.95.65]: Connection refused)
Nov 22 00:28:52 mathilda postfix/smtp[9286]: connect to smtp2.greghorne.com[64.246.163.13]: Connection timed out (port 25)
Nov 22 00:28:52 mathilda postfix/smtp[9286]: 040481B31: to=<fog@greghorne.com>, relay=none, delay=1579, status=deferred (connect to smtp2.greghorne.com[64.246.163.13]: Connection timed out)
|}

You should look for the queue ID’s that postqueue -p shows, in this example – 040481B31, E4C2E1C7B. If everything goes well, you should see status=sent, instead of status=deferred.

Holding messages
Holding messages in the queue means that no attempts to deliver this particular message will be made. To put “on hold” a single message:
~# postsuper -h 040481B31

To put on hold all messages:
~# postsuper -h ALL
postsuper: Placed on hold: 6 messages

To put on hold messages from user@domain.com:
~# postqueue -p | awk ‘BEGIN { RS = “” } { if ($7 == “user@domain.com” ) print $1 }’ | tr -d ‘!*’ | postsuper -h –

Release from hold
Once a message was put “on hold”, it comes a time when you want to move it from ”hold” queue to ”deffered” queue or to release it.

Release single message:
~# postsuper -H 040481B31

Release all messages:
~# postsuper -H ALL
postsuper: Released from hold: 6 message
s

To release messages just from user@domain.com
~# postqueue -p | awk ‘BEGIN { RS = “” } { if ($7 == “user@domain.com” ) print $1 }’ | tr -d ‘!*’ | postsuper -H –

Deleting messages from queue 
Deleting messages from queue is as easy as putting them “on hold”. Be cautious when playing with this option, it’s unreversible.

To delete a single message:
~# postuper -d 040481B31

To delete all messages:
~# postsuper -d ALL

To delete messages from user@domain.com
~# postqueue -p | awk ‘BEGIN { RS = “” } { if ($7 == “user@domain.com” ) print $1 }’ | tr -d ‘!*’ | postsuper -d –

Resources
postsuper(1) and postqueue(1) man pages.

(Collected from http://ramnik.net/wp/?p=5  , thanks for listing it nicely)

Advertisements
Categories: centOS, Fedora 12
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: