{"id":1017,"date":"2014-10-14T14:15:46","date_gmt":"2014-10-14T13:15:46","guid":{"rendered":"http:\/\/blogs.silicontechnix.com\/?p=1017"},"modified":"2014-11-24T14:44:08","modified_gmt":"2014-11-24T14:44:08","slug":"playing-with-exim-mail-queue","status":"publish","type":"post","link":"https:\/\/blogs.silicontechnix.com\/?p=1017","title":{"rendered":"Playing with exim mail queue"},"content":{"rendered":"<p><strong>Command to view the queue<\/strong><\/p>\n<p>To view the exim mail queue issue the following command:<\/p>\n<pre class=\"brush:bash\">mailq<\/pre>\n<p>OR<\/p>\n<pre class=\"brush:bash\">exim -bp<\/pre>\n<p>If exim is in \/usr\/sbin and \/usr\/sbin is not in your path, you&#8217;ll need to prefix the command with the full path like so:<\/p>\n<pre class=\"brush:bash\">\/usr\/sbin\/exim -bp<\/pre>\n<p>Example output<br \/>\nThe outut from the above commands will look something like so:<\/p>\n<pre class=\"brush:bash\">4d  1.2K 1Ka6u5-00032Z-Eb &lt;from@example.com&gt;\r\n\t          to@example.com\r\n\t62h  1.2K 1KaRH0-0007QZ-B5 &lt;from@example.com&gt;\r\n\t          to@example.com\r\n\t3h   22K 1KbLHr-0004ev-An &lt;from@example.com&gt;\r\n\t          to@example.com\r\n<\/pre>\n<p>In the above example &#8220;from@example.com&#8221; is the email address the email is being sent from and to@example.com is the address being sent to. Normally these would be real email addresses but I&#8217;ve changed them for the purposes of this post.<\/p>\n<p>The 4d, 62h and 3h values indicate how long the email message has been in the queue: 4 days, 62 hours and 3 hours respectively.<\/p>\n<p>The x.xK values are the message size.<\/p>\n<p>And the 1Ka6u5-00032Z-Eb etc is the message id and is also the filename of the message on disk, which you will find in \/var\/spool\/exim\/msglog and \/var\/spool\/exim\/input (the directories may vary depending on your Linux\/Unix distribution and\/or compiled in settings).<\/p>\n<p><strong>Finding the files with the find command<\/strong><\/p>\n<p>Using the &#8220;find&#8221; command you could do this to locate all the relevent files:<\/p>\n<pre class=\"brush:bash\">find \/var\/spool\/exim -name \"1Ka6u5-00032Z-Eb*\"<\/pre>\n<p>which would display something like this:<br \/>\nview sourceprint?<\/p>\n<pre class=\"brush:bash\">\/var\/spool\/exim\/msglog\/1Ka6u5-00032Z-Eb\r\n\/var\/spool\/exim\/input\/1Ka6u5-00032Z-Eb-D\r\n\/var\/spool\/exim\/input\/1Ka6u5-00032Z-Eb-H<\/pre>\n<p><strong>Command to flush the exim queue<\/strong><br \/>\nThere are two ways to flush the exim mail queue:<\/p>\n<pre class=\"brush:bash\">runq<\/pre>\n<p>or<\/p>\n<pre class=\"brush:bash\">exim -q<\/pre>\n<p>This will then process the mail queue. I had a look at the exim log file and the mail queue itself (I&#8217;ll be posting how to view what&#8217;s in the exim mail queue on Tuesday) after flushing the queue and the emails were still stuck there.<br \/>\nAdditional flags to force mail send<\/p>\n<p>Another quick look at the exim man page and I discovered the following options:<\/p>\n<p>-qf = If one f flag is present, a delivery attempt is forced for each non-frozen message, whereas without f only those non-frozen addresses that have passed their retry times are tried.<\/p>\n<p>-qff = If ff is present, a delivery attempt is forced for every message, whether frozen or not.<\/p>\n<p>So I then ran this:<\/p>\n<pre class=\"brush:bash\">exim -qff<\/pre>\n<p>And the messages that were stuck in the queue were flushed and delivered. My customer reported back to me a few minutes later that their emails had been received.<br \/>\nPath to exim command<\/p>\n<p>Note that the exim command is probably in \/usr\/sbin and you may need to use the whole path as well as the command to run it. If this is the case then do this:<br \/>\nview sourceprint?<\/p>\n<pre class=\"brush:bash\">\/usr\/sbin\/exim -q\r\n\/usr\/sbin\/exim -qff\r\netc<\/pre>\n<p><strong>Delete a single message from the exim mail queue<\/strong><\/p>\n<p>Use mailq \/ exim -bp to show the mail queue, e.g.:<\/p>\n<pre class=\"brush:bash\">$ mailq\r\n0m   528 1XoIxD-0001rc-8J<\/pre>\n<p>And then run exim -Mrm [message id] to delete the specific message:<\/p>\n<pre class=\"brush:bash\">exim -Mrm 1XoIxD-0001rc-8J<\/pre>\n<p>If the message is successfully deleted, you&#8217;ll see this:<\/p>\n<pre class=\"brush:bash\">Message 1XoIxD-0001rc-8J has been removed<\/pre>\n<p>If exim is currently processing the message, you&#8217;ll see this and it won&#8217;t be deleted:<\/p>\n<pre class=\"brush:bash\">Message 1XoIxD-0001rc-8J is locked<\/pre>\n<p>You either need to wait and try again later, or get the id of the process which is currently processing the message, kill it, and then run the command again (e.g. &#8220;ps ax 1XoIxD-0001rc-8J&#8221; and then &#8220;kill -9 [process id\/s]). It&#8217;s probably not recommended that you kill the process.<br \/>\nDelete all messages in the exim mail queue<\/p>\n<p>Running &#8220;exiqgrep -i&#8221; returns all the message ids for queued emails; pipe that through &#8220;exim -Mrm&#8221; and all the messages will be deleted, with the same caveat as above: if exim is currently processing a message, that one will not be deleted so you need to try again later.<\/p>\n<pre class=\"brush:bash\">exiqgrep -i | xargs exim -Mrm<\/pre>\n<p>And the result, if one could be removed and another one couldn&#8217;t:<\/p>\n<pre class=\"brush:bash\">Message 1XoJ1U-0001sC-ME has been removed<\/pre>\n<pre class=\"brush:bash\">Message 1XoJ1i-0001sQ-UJ is locked<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Command to view the queue To view the exim mail queue issue the following command: mailq OR exim -bp If exim is in \/usr\/sbin and \/usr\/sbin is not in your path, you&#8217;ll need to prefix the command with the full path like so: \/usr\/sbin\/exim -bp Example output The outut from the above commands will look [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"no","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[95],"tags":[461,19,464,462,463],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-system-administration","tag-exim","tag-linux","tag-mail-queue","tag-mail-server","tag-queue"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p12j6H-gp","_links":{"self":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1017"}],"version-history":[{"count":3,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/1017\/revisions"}],"predecessor-version":[{"id":1020,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=\/wp\/v2\/posts\/1017\/revisions\/1020"}],"wp:attachment":[{"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.silicontechnix.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}