<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Postfix_Mail_Queue_Commands_for_Reviewing_Emails</id>
		<title>Postfix Mail Queue Commands for Reviewing Emails - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Postfix_Mail_Queue_Commands_for_Reviewing_Emails"/>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Postfix_Mail_Queue_Commands_for_Reviewing_Emails&amp;action=history"/>
		<updated>2026-06-04T04:05:14Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://briansnelson.com/index.php?title=Postfix_Mail_Queue_Commands_for_Reviewing_Emails&amp;diff=1025&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;==Postfix Mail Queue Commands for Reviewing Emails==  '''How to review the email message your server is trying to send.'''  There are two queues within Postfix: pending and di...&quot;</title>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Postfix_Mail_Queue_Commands_for_Reviewing_Emails&amp;diff=1025&amp;oldid=prev"/>
				<updated>2019-07-23T01:27:54Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Postfix Mail Queue Commands for Reviewing Emails==  &amp;#039;&amp;#039;&amp;#039;How to review the email message your server is trying to send.&amp;#039;&amp;#039;&amp;#039;  There are two queues within Postfix: pending and di...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Postfix Mail Queue Commands for Reviewing Emails==&lt;br /&gt;
&lt;br /&gt;
'''How to review the email message your server is trying to send.'''&lt;br /&gt;
&lt;br /&gt;
There are two queues within Postfix: pending and differed. &lt;br /&gt;
&lt;br /&gt;
The pending queue includes all messages that have been submitted to postfix which have not yet been sent out and handed off to the recipient server. &lt;br /&gt;
&lt;br /&gt;
The differed mail queue holds all messages that have soft-failed and need to be retired (temporary failure). Postfix will retry sending the deferred queue on set intervals (this is configurable, but is set to 5 minutes as a default).&lt;br /&gt;
&lt;br /&gt;
The following commands will allow you to review these queues:&lt;br /&gt;
&lt;br /&gt;
===1- Display the mail queues, deferred and pending===&lt;br /&gt;
&lt;br /&gt;
 mailq&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 postqueue -p&lt;br /&gt;
&lt;br /&gt;
To save the output to a text file you can run:&lt;br /&gt;
&lt;br /&gt;
 mailq &amp;gt; mailqueue.txt&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
 postqueue -p &amp;gt; mailqueue.txt&lt;br /&gt;
&lt;br /&gt;
Either of these commands will show you all queued messages.&lt;br /&gt;
&lt;br /&gt;
NB: this command shows the sender and recipients and ID, not the message itself. The ID is particularly useful if you want to inspect the message itself.&lt;br /&gt;
&lt;br /&gt;
===2- View message (contents, header and body) in Postfix queue===&lt;br /&gt;
&lt;br /&gt;
To view a message with the ID XXXXXXX&lt;br /&gt;
&lt;br /&gt;
(you can see the ID from the queue)&lt;br /&gt;
&lt;br /&gt;
 postcat -vq XXXXXXXXXX&lt;br /&gt;
&lt;br /&gt;
Or to save it in a file&lt;br /&gt;
&lt;br /&gt;
 postcat -vq XXXXXXXXXX &amp;gt; emailXXXXXXXXXX.txt&lt;br /&gt;
&lt;br /&gt;
A useful feature for web servers is to enable mail.add_x_header = on in the Postfix configuration. This will add a header to all outgoing email messages showing the script and user that generated each message.  Once enabled this will then add the following extra header to message:&lt;br /&gt;
&lt;br /&gt;
'''X-PHP-Originating-Script: 1001:spamEmailer.php'''&lt;br /&gt;
&lt;br /&gt;
In this example 1001 is the UID and the spamEmailer.php was the script sending the message. This can allow you to quickly track down the source of spam messages being sent by your server.&lt;br /&gt;
&lt;br /&gt;
With these commands you should be able to review your mail queue and make sure that intended messages are being sent and have not been rejected.&lt;br /&gt;
&lt;br /&gt;
==How to delete queued mail from the postfix mail queue==&lt;br /&gt;
&lt;br /&gt;
Now that we have learned the necessary steps to reviewing your mail queue, the final 3 tips will demonstrate how to delete queued mail.&lt;br /&gt;
&lt;br /&gt;
===3- Tell Postfix to process the queue now===&lt;br /&gt;
&lt;br /&gt;
 postqueue -f&lt;br /&gt;
&lt;br /&gt;
OR&lt;br /&gt;
&lt;br /&gt;
 postfix flush&lt;br /&gt;
&lt;br /&gt;
This will cause Postfix to immediately attempt to send all queued messages.&lt;br /&gt;
&lt;br /&gt;
===4- Delete queued mail===&lt;br /&gt;
&lt;br /&gt;
Delete all queued mail&lt;br /&gt;
&lt;br /&gt;
 postsuper -d ALL&lt;br /&gt;
&lt;br /&gt;
Delete only the differed mail queue messages (i.e. only the ones the system intends to retry later)&lt;br /&gt;
&lt;br /&gt;
 postsuper -d ALL deferred&lt;br /&gt;
&lt;br /&gt;
===5- Delete mail from the queue selectively===&lt;br /&gt;
&lt;br /&gt;
This is not something that is natively included with the standard Postfix tools however can be done with a bit of Perl scripting.&lt;br /&gt;
&lt;br /&gt;
NB: This perl script seems to be free, and is all over the internet however I could not find out where it originates or who wrote it but my thanks go to them!&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
 #!/usr/bin/perl&lt;br /&gt;
 &lt;br /&gt;
 $REGEXP = shift || die “no email-adress given (regexp-style, e.g. bl.*\@yahoo.com)!”;&lt;br /&gt;
 &lt;br /&gt;
 @data = qx;&lt;br /&gt;
 &lt;br /&gt;
 for (@data) {&lt;br /&gt;
 &lt;br /&gt;
   if (/^(\w+)(\*|\!)?\s/) {&lt;br /&gt;
 &lt;br /&gt;
      $queue_id = $1;&lt;br /&gt;
 &lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
   if($queue_id) {&lt;br /&gt;
 &lt;br /&gt;
     if (/$REGEXP/i) {&lt;br /&gt;
 &lt;br /&gt;
       $Q{$queue_id} = 1;&lt;br /&gt;
 &lt;br /&gt;
       $queue_id = “”;&lt;br /&gt;
 &lt;br /&gt;
     }&lt;br /&gt;
 &lt;br /&gt;
   }&lt;br /&gt;
 &lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
  #open(POSTSUPER,”|cat”) || die “couldn’t open postsuper” ;&lt;br /&gt;
 &lt;br /&gt;
 open(POSTSUPER,”|postsuper -d -“) || die “couldn’t open postsuper” ;&lt;br /&gt;
 &lt;br /&gt;
  foreach (keys %Q) {&lt;br /&gt;
 &lt;br /&gt;
   print POSTSUPER “$_\n“;&lt;br /&gt;
 &lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 close(POSTSUPER);&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Usage Examples:&lt;br /&gt;
&lt;br /&gt;
'''Delete all queued messages to or from the domain called spamers.com, enter:&lt;br /&gt;
&lt;br /&gt;
 ./postfix-delete.pl spamers.com&lt;br /&gt;
&lt;br /&gt;
Delete all queued messages that contain the word “spam” in the e-mail address:&lt;br /&gt;
&lt;br /&gt;
 ./postfix-delete.pl spam&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>