How to Inspecting email queue

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,


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

./ spam

Now you know how to manage mails in server.




Related posts

Leave a Comment