How to review the email message your server is trying to send.
The following commands will allow you to review these queues:
1- Display the mail queues, deferred and pending
To save the output to a text file you can run:
mailq > mailqueue.txt
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:
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
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