You are on page 1of 6

21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

☰ NAVIGAT ION

JON TOTHAM
SENIOR SYSTEMS ADMINISTRATOR
WIREHIVE
SHARE

   

THOUGHTS

5 top tips for reviewing your Postfix mail


queue
How to review the email message your server is trying to send.

There are two queues within Postfix: pending and differed. The pending queue
includes all messages that have been submitted to postfix which have not yet Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 1/6
21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

been sent out and handed off to the recipient server. The differed mail queue
holds all messages that have soft-failed and☰ need
NAVIGAT ION
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).

The following commands will allow you to review these queues:

1- Display the mail queues, deferred and pending

mailq

or

postqueue -p

To save the output to a text file you can run:

mailq > mailqueue.txt

or

postqueue -p > mailqueue.txt

Either of these commands will show you all queued messages.

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.

2- View message (contents, header and body) in Postfix queue

To view a message with the ID XXXXXXX

(you can see the ID from the queue)

postcat -vq XXXXXXXXXX

Or to save it in a file

postcat -vq XXXXXXXXXX > emailXXXXXXXXXX.txt

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:
Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 2/6
21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

X-PHP-Originating-Script: 1001:spamEmailer.php
☰ NAVIGAT ION

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.

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.

How to delete queued mail from the mail queue

Now that we have learned the necessary steps to reviewing your mail queue, the
final 3 tips will demonstrate how to delete queued mail.

3- Tell Postfix to process the queue now

postqueue -f

OR

postfix flush

This will cause Postfix to immediately attempt to send all queued messages.

4- Delete queued mail

Delete all queued mail

postsuper -d ALL

Delete only the differed mail queue messages (i.e. only the ones the system
intends to retry later)

postsuper -d ALL deferred

5- Delete mail from the queue selectively

This is not something that is natively included with the standard Postfix tools
however can be done with a bit of Perl scripting.

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!

#########################################
Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 3/6
21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

#!/usr/bin/perl
☰ NAVIGAT ION

$REGEXP = shift || die “no email-adress given (regexp-style, e.g.


bl.*\@yahoo.com)!”;

@data = qx;

for (@data) {

  if (/^(\w+)(\*|\!)?\s/) {

     $queue_id = $1;

 }

  if($queue_id) {

    if (/$REGEXP/i) {

      $Q{$queue_id} = 1;

      $queue_id = “”;

    }

 }

 #open(POSTSUPER,”|cat”) || die “couldn’t open postsuper” ;

open(POSTSUPER,”|postsuper -d -“) || die “couldn’t open postsuper” ;

 foreach (keys %Q) {

  print POSTSUPER “$_\n“;

};

close(POSTSUPER);

#########################################

Usage Examples:

Delete all queued messages to or from the domain called spamers.com, enter: Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 4/6
21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

./postfix-delete.pl spamers.com
☰ NAVIGAT ION

Delete all queued messages that contain the word “spam” in the e-mail address:

./postfix-delete.pl spam

If you’re having trouble with your mail server, and this hasn’t helped you fix things
why not give us a call?

SIMILAR POSTS

1 8.02.19
Using Amazon Web Services Applications to run your Business
When Amazon Web Services (AWS) is mentioned, you likely think of cloud based
services such as autoscaling websites, multi-regional support and other more
well known things.  However there are a whole range of Amazon Web Services
applications that you may not have come across.  Those services relating to
business productivity.

Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 5/6
21-06-2019 5 top tips for reviewing your Postfix mail queue | Wirehive

☰ NAVIGAT ION

30.1 1.18
Understanding Cloud Services – Stateful vs Stateless Applications
To be able to make the most of the services available within public cloud hosting
it is necessary to create a stateless application.

In this article we look at the difference between stateful and stateless, and why it
matters.

SEE ALL POSTS

Terms and Conditions Compliance Acceptable Use Policy Terms Of Use


FX Rates Cookies Credits
© 2019 Wirehive. All rights reserved. | Company number 05451011 | VAT number
850236839

  

Privacidad - Condiciones

https://www.wirehive.com/thoughts/5-top-tips-reviewing-postfix-mail-queue/ 6/6

You might also like