UPDATE 2021-04-18:
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 ~ /@example\.com/ && $9 == "") print $1 }' | tr -d '*!' | postsuper -d -
Whereas $7
=sender, $8
=recipient1, $9
=recipient2. You can also adapt the rule for other recipients ($9
) to your needs.
The command is based on an example of the postsuper manpage which an example command matching a full recipient mail address:
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 == "user@example.com" && $9 == "") print $1 }' | tr -d '*!' | postsuper -d -
Old content:
This command deletes all mails sent from or to addresses that end with @example.com
:
sudo mailq | tail -n +2 | awk 'BEGIN { RS = "" } /@example\.com$/ { print $1 }' | tr -d '*!' | sudo postsuper -d -