Postfix Mail Queue Management
To view the number of emails in the Postfix mail queue
mailq
Postfix delete mail queue: postsuper command
To delete all emails in the queue
postsuper -d ALL
To remove all mails in the deferred queue
postsuper -d ALL deferred
To remove a particular mail from the queue
postsuper -d mail_id
To remove messages from a particular domain.
mailq | grep xdomain.com | awk {'print $1'} | xargs -I{} postsuper -d {}
To remove all mails from a particular mail id
mailq | tail +2 | awk 'BEGIN { RS = "" } / testmail@xdomain\.com$/ { print $1 }' | tr -d '*!' | postsuper -d -
To remove all mails which have testmail@xdomain.com in the entire mail.
for id in `postqueue -p|grep '^[A-Z0-9]'|cut -f1 -d' '|sed 's/*//g'`; do postcat -q $id | grep testmail@domain.com && postsuper -d $id; done
To remove all mails which have a particular pattern like “.de”
for id in `postqueue -p|grep '^[A-Z0-9]'|cut -f1 -d' '|sed 's/*//g'`; do postcat -q $id | grep “.de” && postsuper -d $id; done
Postfix queue structure
/var/spool/postfix/maildrop /var/spool/postfix/hold /var/spool/postfix/incoming /var/spool/postfix/active /var/spool/postfix/deferred /var/spool/postfix/corrupt
Display the list of Queued mails , deferred mails, and Pending mails
postqueue -p
To Display the mail header and contents
postcat -q “Queue ID”
To check the total number of mails in the queue
postqueue -p | grep -c "^[A-Z0-9]"
To attempt to send one particular mail
postqueue -i “Queue ID”
Force mails on Postfix
To reattempt delivery of all mails in the queue
postqueue -f