{"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&#038;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<div data-elementor-type=\"wp-post\" data-elementor-id=\"20719\" class=\"elementor elementor-20719\" data-elementor-post-type=\"kb\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9b99875 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9b99875\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ac4fb61\" data-id=\"ac4fb61\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c9f217c elementor-widget elementor-widget-heading\" data-id=\"c9f217c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">To find which mails are stuck in mail queue and why?<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2030ab6 elementor-widget elementor-widget-text-editor\" data-id=\"2030ab6\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Postfix Queue Management. If emails are getting delay, it&#8217;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<div class=\"elementor-element elementor-element-0b7fac3 elementor-widget elementor-widget-heading\" data-id=\"0b7fac3\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Status\/Shape of Mail Queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-372dbdb elementor-widget elementor-widget-text-editor\" data-id=\"372dbdb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Postfix maintains different queues for different purpose.<code>active<\/code>\u00a0 and \u00a0<code>deferred<\/code>\u00a0queues are of our interest.<\/p><p>Ideally, we should never have a mail in deferred queue.<\/p><p><code>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><pre><code>qshape<\/code><\/pre><p><strong>Sample Outputs:<\/strong><\/p><pre><code>       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><p>If a mail is deferred, it will be moved to deferred\u00a0queue.<\/p><p>Running following command will show you the number of deferred emails for each domains\u2026<\/p><pre><code>qshape deferred<\/code><\/pre><p><strong>Sample Output:<\/strong><\/p><pre><code>               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><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><p>Analyze mails in queue<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-78da055 elementor-widget elementor-widget-heading\" data-id=\"78da055\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Dump entire mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-3290af3 elementor-widget elementor-widget-text-editor\" data-id=\"3290af3\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>You can use either\u00a0<code>mailq<\/code>\u00a0or\u00a0<code>postqueue -p<\/code>command. They will show an output like below:<\/p><pre><code>-Queue ID- --Size-- ----Arrival Time---- -Sender\/Recipient-------\n<strong>2FC8824D24<\/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><p>You get a dump for all emails from all mail queues including active &amp; deferred queues.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-123f22c elementor-widget elementor-widget-heading\" data-id=\"123f22c\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Read an email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2e922de elementor-widget elementor-widget-text-editor\" data-id=\"2e922de\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Every message in the queue has a unique id. You can read the message in a queue using a command like:<\/p><pre><code>postcat -q \u00a0DA80E24A0A<\/code><\/pre><p>Or<\/p><pre><code>postcat -qv \u00a0DA80E24A0A<\/code><\/pre><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<div class=\"elementor-element elementor-element-a1763e8 elementor-widget elementor-widget-heading\" data-id=\"a1763e8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Attempt to send an email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bc2188d elementor-widget elementor-widget-text-editor\" data-id=\"bc2188d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>It&#8217;s better to first open the postfix log using something like below:<\/p><pre><code>tail -f \/var\/log\/mail.{err,log}<\/code><\/pre><p>Then you can identify a stuck mail and attempt to send it by using:<\/p><pre><code>postqueue -i DA80E24A0A<\/code><\/pre><p>If that mail gets stuck again, check the log tab to find the reason.<\/p><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<div class=\"elementor-element elementor-element-af8a333 elementor-widget elementor-widget-heading\" data-id=\"af8a333\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Attempt to send all email from mail queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-339f32d elementor-widget elementor-widget-text-editor\" data-id=\"339f32d\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Once you rectify the issue and confident about a delivery, you may try flushing the entire queue immediately using:<\/p><pre><code>postqueue -f<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-f0f6ed8 elementor-widget elementor-widget-heading\" data-id=\"f0f6ed8\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Deleting Pending mails from queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-87a2c0f elementor-widget elementor-widget-text-editor\" data-id=\"87a2c0f\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>In that case, you can simply delete all queued mails using:<\/p><pre><code>postsuper -d ALL deferred<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ff4e337 elementor-widget elementor-widget-heading\" data-id=\"ff4e337\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Delete a single mail from the queue<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-59ddf73 elementor-widget elementor-widget-text-editor\" data-id=\"59ddf73\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>If you want to just delete one mail, you can try:<\/p><pre><code>postsuper -d DA80E24A0A<\/code><\/pre>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9bdd209 elementor-widget elementor-widget-heading\" data-id=\"9bdd209\" data-element_type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\">Delete mails to a specific mail address<\/h2>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-61756a9 elementor-widget elementor-widget-text-editor\" data-id=\"61756a9\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>You need to some work here as postfix has no direct command for this.<\/p><p>The following sample is taken from postsuper man page:<\/p><pre><code>mailq | tail -n +2 | grep -v '^ *(' | awk  'BEGIN { RS = \"\" } { if ($8 == \"USER@EXAMPLE.COM\" &amp;&amp; $9 == \"\") print $1 } ' | tr -d '*!' | postsuper -d -<\/code><\/pre><p>Just replace USER@EXAMPLE.COM with the receiver&#8217;s email address.<\/p><p><code>$8<\/code>\u00a0will contain\u00a0recipient1 email-address,\u00a0<code>$9<\/code>\u00a0will contain\u00a0recipient2 email-address.<\/p><p>If you want to filter from-email address, use\u00a0<code>$7<\/code>\u00a0variable.<\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-82525cb elementor-widget elementor-widget-text-editor\" data-id=\"82525cb\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<p>Click to read the next recommended article: <a href=\"https:\/\/www.casbay.com\/guide\/kb\/7-extremely-useful-linux-commands\/\">7 Useful Linux Commands<\/a><\/p>\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>To find which mails are stuck in mail queue and why? Postfix Queue Management. If emails are getting delay, it&#8217;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\u00a0 and \u00a0deferred\u00a0queues are of our interest. Ideally, we should never have a mail [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"page-builder","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"default","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}}},"kbtopic":[109],"kbtag":[106,105],"mkb_version":[],"_links":{"self":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/20719"}],"collection":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/comments?post=20719"}],"version-history":[{"count":2,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/20719\/revisions"}],"predecessor-version":[{"id":31718,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kb\/20719\/revisions\/31718"}],"wp:attachment":[{"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/media?parent=20719"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=20719"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/kbtag?post=20719"},{"taxonomy":"mkb_version","embeddable":true,"href":"https:\/\/www.casbay.com\/guide\/wp-json\/wp\/v2\/mkb_version?post=20719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}