Managing the Postfix Email System

Once you have it running postfix rarely needs any needs much looking after. This means that when you do get an issue, you may be a bit rusty about what to do to fix things. Here are a few pointers to a few commands that can help. We are running debian 7.6 (wheezy) on our servers, so all examples below have been tested in this environment.

Listing the emails waiting in the queue.

Listing all emails



postqueue -p

These are just aliases for the same command and give ther same output:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
107EDD8028*   39013 Wed Dec 17 10:26:50  MAILER-DAEMON

4D024320B44*    2311 Fri Dec 19 16:05:12
-- 816 Kbytes in 2 Requests.

You can add the -v flag to postqueue to get additional debugging information.

List all emails to or from a particular user

You can filter the results from mailq with awk:

mailq | awk 'BEGIN {RS="" } /'

List all the Queue ID’s to or from a particular user

mailq | tail -n +2 | head -n -1 | awk 'BEGIN {RS="" } / {print $1}| tr -d '*!' '

tail and head are used to strip the first and last lines of the report, which are the title and summary lines. The tr is to remove the * and ! status flags that mailq adds to the queue ids.

Viewing the contents of messages in the queue

Once you have a list of the messages in the queue, you are likely to want to view one. You can do this with the Queue ID from the section above.

Viewing a single message

# postcat -q 107EDD8028

The -q tells postcat to search all the queue folders for the message.
You can also add an additional -v for verbose output.

Viewing all emails to or from a specific address

If you have a lot of messages queued to/from a particular user, it maybe useful to take a look to see if they are spam.

postcat -q `mailq | tail -n +2 | head -n -1 | awk 'BEGIN {RS="" } / {print $1}'| tr -d '*!'`

Removing messages from the queue

Removing a single message

Sometimes you may want to get rid of a message in the queue.

postsuper -d 107EDD8028

Removing all messages to/from a specific address

If an address/domain is sending a lot of spam, this is really helpfull to clear the queue

mailq | tail -n +2 | head -n -1 | awk 'BEGIN {RS="" } / {print $1}' | tr -d '*!' | postsuper -d -

Removing all messages in the queue

If the whole queue is spam or it is too huge to diagnose, you can delete the whole queue. This is best applied just to the deferred queue otherwise you could be removing emails that might still be delivered, but you can leave out the deferred argument to remove all queued emails in an emergency.

postsuper -d ALL deferred

Flushing the queue

Once you have fixed an issue, and want postfix to re-try to deliver them, you can flush the queue:

postqueue -f

Date: December 19, 2014

Category: Linux Admin Tips

Author: John Taylor

Respond To This Post: