This is the shortest cheat sheet for those who just started working with Postfix and needs to do something with the mail queue.
Postfix maintains two queues, the pending mail 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 (default = 5 minutes).
Below are the most used commands to manipulate the queue:
Display a list of mail queues, deferred and pending
mailq
or
postqueue -p
View a message (contents, headers and body) with a specific ID
postcat -vq <ID>
<id> ::= XXXXXXXX, e.g. 2B2D742031
Flush the queue (tell Postfix to process all mails now)
postqueue -f
Delete all queued mails
postsuper -d ALL
Delete all deferred mails
postsuper -d all deferred
Delete mails selectively (delete if recipient = [email protected])
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "[email protected]" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d -