How to view messages in the postfix queue
1- Postfix maintains two queues, the pending mails queue, and the deferred mail queue, the deferred mail queue has the mail that has soft-fail and should be retried (Temporary failure), Postfix retries the deferred queue on set intervals (configurable, and by default 5 minutes).
1- Display a list of queued mail, deferred and pending
mailq or postqueue -p
To save the output to a text file you can run.
mailq > myfile.txt or postqueue -p > myfile.txt
The above commands display all queued messages (Not the message itself but the sender and recipients and ID), The ID is particularly useful if you want to inspect the message itself.
2- View message (contents, header and body) in Postfix queue
Assuming the message has the ID XXXXXXX (you can see the ID form the QUEUE)
postcat -vq XXXXXXXXXX
Or to save it in a file
postcat -vq XXXXXXXXXX > themessage.txt
3- Tell Postfix to process the Queue now
postqueue -f or postfix flush
4- Delete queued mail
postsuper -d ALL
Delete differed mail queue messages
(The ones the system intends to retry later)
postsuper -d ALL deferred
Delete from queue selectively
To delete from the queue all emails that have a certain address in them, we can use this program (perl script)…
NOTE: This perl script seems to be free, and is all over the internet, i could not find out where it originates or who wrote it.
Delete all queued messages to or from the domain called example.com,
/postfix-delete.pl example.com
Delete all queued messages that contain the word “spam” in the e-mail address:
./postfix-delete.pl spam
Now you know how to manage mails in server.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?