Casbay Knowledge Base

Search our articles or browse by category below

Postfix Queue Management

Last updated: September 7, 2022
Estimated reading time: 2 min

To find which mails are stuck in mail queue and why?

Postfix Queue Management. If emails are getting delay, it’s better to inspect postfix mail queues, coupled with postfix mail log.

Status/Shape of Mail Queue

Postfix maintains different queues for different purpose.active  and  deferred queues are of our interest.

Ideally, we should never have a mail in deferred queue.

qshape command will show shape of active mail queue by default. Ideally it should be as close as to empty since postfix sends email instantly!

qshape

Sample Outputs:

       T  5 10 20 40 80 160 320 640 1280 1280+
TOTAL  0  0  0  0  0  0   0   0   0    0     0

If a mail is deferred, it will be moved to deferred queue.

Running following command will show you the number of deferred emails for each domains…

qshape deferred

Sample Output:

               T  5 10 20 40 80 160 320 640 1280 1280+
        TOTAL  5  0  0  0  0  0   0   0   0    0     5
    gmail.com  4  0  0  0  0  0   0   0   0    0     4
    yahoo.com  1  0  0  0  0  0   0   0   0    0     1

If you see mails to one or more domain only being deferred, check if you can connect to those servers from your network.

Analyze mails in queue

Dump entire mail queue

You can use either mailq or postqueue -pcommand. They will show an output like below:

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
2FC8824D24    10588 Thu Sep 27 14:52:41  [email protected]
(connect to alt2.gmail-smtp-in.l.google.com[74.125.79.26]:25: Connection timed out)
                                         [email protected]
-- 16 Kbytes in 2 Requests.

You get a dump for all emails from all mail queues including active & deferred queues.

Read an email from mail queue

Every message in the queue has a unique id. You can read the message in a queue using a command like:

postcat -q  DA80E24A0A

Or

postcat -qv  DA80E24A0A

It will display your emails with headers and some more info. Using ‘v’ will display extra information.

Attempt to send an email from mail queue

It’s better to first open the postfix log using something like below:

tail -f /var/log/mail.{err,log}

Then you can identify a stuck mail and attempt to send it by using:

postqueue -i DA80E24A0A

If that mail gets stuck again, check the log tab to find the reason.

Once you fix the issue, you can attempt to send that mail again. Mail ID inside queue remains same even if mail gets deferred again and again.

Attempt to send all email from mail queue

Once you rectify the issue and confident about a delivery, you may try flushing the entire queue immediately using:

postqueue -f

Deleting Pending mails from queue

In that case, you can simply delete all queued mails using:

postsuper -d ALL deferred

Delete a single mail from the queue

If you want to just delete one mail, you can try:

postsuper -d DA80E24A0A

Delete mails to a specific mail address

You need to some work here as postfix has no direct command for this.

The following sample is taken from postsuper man page:

mailq | tail -n +2 | grep -v '^ *(' | awk  'BEGIN { RS = "" } { if ($8 == "[email protected]" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d -

Just replace [email protected] with the receiver’s email address.

$8 will contain recipient1 email-address, $9 will contain recipient2 email-address.

If you want to filter from-email address, use $7 variable.

Click to read the next recommended article: 7 Useful Linux Commands

Was this article helpful?
Dislike 0
Previous: 2 Linux Based VPS Tips On Configuring Sudoers File
Next: TIPS: IIS 6.0 – Security Best Practices
Discover the perfect balance of performance and budget-friendly Dedicated Server plan !
Discover the perfect balance of performance and budget-friendly Dedicated Server plan !
High performance and low cost Dedicated Server plan 128GB from $185 – upgrade today!
High performance and cheap Dedicated Server plan 128GB from $185 – upgrade today!