How to flush the mailq of a particular email address

 

The follow commands must exist on the server for you to utilize. Furthermore you will need to be a user with root like credentials.

  • mailq
  • postuser

mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "emailaddress@domain.tld" && $9 == "") print $1 } ' | tr -d '*!' | postsuper -d - > /emailaddress_results.txt

 

Note, that the search term is case-sensitive. If the email address happens to be case sensitive, you will not be able to catch all the emails in 1st try and will have to run it again. It is best you create multiple result text files.

To determine how many messages were removed, run the following command:

grep emailaddress_results.txt | wc -l