Published : 2014-09-11

Remove specific mails from the queue

In some cases you may be spammed by a specific user. In such case it can be interesting to remove all mails in the queue coming from this user to prevent your mailboxes from filling up.

The following command removes all mails coming from a user and prints the number of removed mails at the end.

mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($7 == "spammer@gmail.com")print $1 }' | tr -d '*!' | postsuper -d -

Using grep is wise rather than tail, as it saves time by processing the mail while reading the queue rather than after a full read.