I.T. Security and Linux Administration

Sep 18 2011   6:57PM GMT

Postfix and Post Queue

Eric Hansen Eric Hansen Profile: Eric Hansen

A lot of talk and discussions can be found online in regards to mail systems like sendmail, Qmail, etc…but, at least for me, Postfix is more of the silent assassin of sorts.  Out of the systems though, I’d have to say Postfix is one of the easier and more versatile MTA’s to use for Linux.  sendmail is sort of the de facto standard, and Postfix has always been intended to be a superset of sendmail.  In this post, I’d like to discuss the mail queue, and how to handle it.

There’s two commands you can use for Postfix queue management.  The first, which requires super user rights, is postsuper.  This gives you complete control, but might be a little over-complicated for some matters.  The other, which does not require super user rights, is postqueue.  The man page illustrates the difference between the two as the following:

See the postsuper(1) command for queue operations that require super-user privileges such as  deleting a message from the queue or changing the status of a message.

However, if you would like to investigate the queue (see what’s stuck in there, for example), you can use the following command:

postqueue -p

Output from this looks similar to this (gotta love tired e-mail testing):

-Queue ID- –Size– —-Arrival Time—- -Sender/Recipient——-
CAE811FEC5      346 Fri Sep 16 22:21:07  dns@<domain.tld>
(Host or domain name not found. Name service error for name=blah.com type=MX: Host not found, try again)

— 0 Kbytes in 1 Request.

A couple of other useful commands with postqueue is trying to resend mail that’s stuck in the queue (postqueue -i <queue id> [i.e.: postqueue -i CAE811FEC5 if I wanted to resend out the mail above]).  While this isn’t fabulous if you have a lot of mail stuck in queue to send out, if there’s one or two stuck, it’s not a big worry.  Another command, which according to man will degrade the mail delivery performance if used excessively, is postqueue -f.  This flushes the queue and attempts to deliver all the mail in the queue.  However, if you want to do this, you’re probably better off writing a script to just parse each line for you, and send it out one by one using postqueue -i…which I might just write pretty soon.

We can’t forget about our super friend, postsuper, though.  postsuper offers the same options as postqueue, with a few more, and a little bit more features to them.  For example, there’s no “flush” option in postsuper, but it does give you the option to requeue the mail with the “-r” command.  However, if you want to requeue all of the mail, for security purposes Postfix has forced you to use postsuper -r ALL.  If you would rather delete mail though, you use the “-d” command.  By default, it takes the queue ID of the mail to be deleted.  However, for both -r and -d, you can pass “-” as the queue ID to handle (which means it will read from standard input/stdin).  You can also pass any of the following queues: hold, incoming, active, deferred.  Like the -r command though, you can use ALL for the queue ID to delete all the mail.  Okay, so besides the basics, you can also put mail on hold “-h <queue id>” and release the hold “-H <queue id>”.  Same queue ID options as -r and -d.

However, if you decide to stop Postfix for any reason, or it crashes, there’s two commands you should run prior to starting it back up.  The first is postsuper -s.  This basically does an integrity check on Postfix’s files and such, and makes sure none are corrupted.  The second is the -p command, which is different than postqueue’s option.  For postsuper, this purges all the temporary files that were left over before Postfix stopped running.  This is especially useful if the lock file exists after Postfix is shut down or crashes, as it’ll prevent Postfix from running again, thinking theres still a process running.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: