NixUser

NixUser.com | Unix User | Linux User | NixUser

Postfix flush Mail Queue (and) by Sender

In Postfix, enter the following command to flush the email queue:

$ postfix flush

Or you can use:

$ postfix -f

To see the mail queue, enter:

$ mailq

Or

$ postqueue -p

To remove all mail from the queue:

$ postsuper -d ALL

To remove all deferred emails in queue:

$ postsuper -d ALL deferred

To delete all mails to or from the mail queue from a specific sender, say user@example.com or that are sent to user@example.com

$ mailq | tail +2 | awk ‘BEGIN { RS = “” } / user@example\.com$/ { print $1 }’ | tr -d ‘*!’ | postsuper -d –

Or

$ postqueue -p | tail -n +2 | awk ‘BEGIN { RS = “” } /user@example\.com/ { print $1 }’ | tr -d ‘*!’ | postsuper -d –

To delete all emails in the queue from a domain:

$ postqueue -p | tail -n +2 | awk ‘BEGIN { RS = “” } /@example\.com/ { print $1 }’ | tr -d ‘*!’ | postsuper -d –