{"id":20719,"date":"2020-11-30T05:29:12","date_gmt":"2020-11-29T21:29:12","guid":{"rendered":"https:\/\/web.mwwsb.com.my\/pjci\/?post_type=kb&p=20719"},"modified":"2022-09-07T20:03:41","modified_gmt":"2022-09-07T12:03:41","slug":"postfix-queue-management","status":"publish","type":"kb","link":"https:\/\/www.casbay.com\/guide\/kb\/postfix-queue-management","title":{"rendered":"Postfix Queue Management"},"content":{"rendered":"\t\t
Postfix Queue Management. If emails are getting delay, it’s better to inspect postfix mail queues, coupled with postfix mail log.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
Postfix maintains different queues for different purpose. Ideally, we should never have a mail in deferred queue.<\/p> Sample Outputs:<\/strong><\/p> If a mail is deferred, it will be moved to deferred\u00a0queue.<\/p> Running following command will show you the number of deferred emails for each domains\u2026<\/p> Sample Output:<\/strong><\/p> If you see mails to one or more domain only being deferred, check if you can connect to those servers from your network.<\/p> Analyze mails in queue<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t You can use either\u00a0 You get a dump for all emails from all mail queues including active & deferred queues.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t Every message in the queue has a unique id. You can read the message in a queue using a command like:<\/p> Or<\/p> It will display your emails with headers and some more info. Using \u2018v\u2019 will display extra information.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t It’s better to first open the postfix log using something like below:<\/p> Then you can identify a stuck mail and attempt to send it by using:<\/p> If that mail gets stuck again, check the log tab to find the reason.<\/p> 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.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t Once you rectify the issue and confident about a delivery, you may try flushing the entire queue immediately using:<\/p> In that case, you can simply delete all queued mails using:<\/p> If you want to just delete one mail, you can try:<\/p> You need to some work here as postfix has no direct command for this.<\/p> The following sample is taken from postsuper man page:<\/p> Just replace USER@EXAMPLE.COM with the receiver’s email address.<\/p> If you want to filter from-email address, use\u00a0active<\/code>\u00a0 and \u00a0deferred<\/code>\u00a0queues are of our interest.<\/p>qshape<\/code>\u00a0command will show shape of active mail queue by default. Ideally it should be as close as to empty since postfix sends email instantly!<\/p>qshape<\/code><\/pre> T 5 10 20 40 80 160 320 640 1280 1280+\nTOTAL 0 0 0 0 0 0 0 0 0 0 0<\/code><\/pre>qshape deferred<\/code><\/pre> T 5 10 20 40 80 160 320 640 1280 1280+\n TOTAL 5 0 0 0 0 0 0 0 0 0 5\n gmail.com 4 0 0 0 0 0 0 0 0 0 4\n yahoo.com 1 0 0 0 0 0 0 0 0 0 1<\/code><\/pre>Dump entire mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
mailq<\/code>\u00a0or\u00a0postqueue -p<\/code>command. They will show an output like below:<\/p>-Queue ID- --Size-- ----Arrival Time---- -Sender\/Recipient-------\n2FC8824D24<\/strong> 10588 Thu Sep 27 14:52:41 from.me@example.com\n(connect to alt2.gmail-smtp-in.l.google.com[74.125.79.26]:25: Connection timed out)\n some.user@gmail.com\n-- 16 Kbytes in 2 Requests.<\/code><\/pre>Read an email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
postcat -q \u00a0DA80E24A0A<\/code><\/pre>postcat -qv \u00a0DA80E24A0A<\/code><\/pre>Attempt to send an email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
tail -f \/var\/log\/mail.{err,log}<\/code><\/pre>postqueue -i DA80E24A0A<\/code><\/pre>Attempt to send all email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
postqueue -f<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\tDeleting Pending mails from queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
postsuper -d ALL deferred<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\tDelete a single mail from the queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
postsuper -d DA80E24A0A<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\tDelete mails to a specific mail address<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = \"\" } { if ($8 == \"USER@EXAMPLE.COM\" && $9 == \"\") print $1 } ' | tr -d '*!' | postsuper -d -<\/code><\/pre>$8<\/code>\u00a0will contain\u00a0recipient1 email-address,\u00a0$9<\/code>\u00a0will contain\u00a0recipient2 email-address.<\/p>$7<\/code>\u00a0variable.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t