Postfix

Delete spam mail

Delete mail which sender is [email protected]

mailq | tail -n +2 | head -n -2 | grep -v '^ (' | awk 'BEGIN { RS = "" } { if (($7 == "[email protected]")) print $1 }' | tr -d '!' | postsuper -d -

Delete bounce mail from the previous command

mailq | tail -n +2 | head -n -2 | grep -v '^ (' | awk 'BEGIN { RS = "" } { if (($8 ~ "[email protected]")) print $1 }' | tr -d '!' | postsuper -d -

Analysis with postfix-perl-scripts

Extract information since today

pflogsumm -D today /var/log/maillog

Extract all invalid recipient from log

pflogsumm -D today /var/log/maillog | grep -i "Invalid Recipient" | awk '{ print $4 }' | tr -d '<' | tr -d '>'

Extract all “User quota exceeded” messages from log:

pflogsumm -D today /var/log/maillog | grep "User quota exceeded" | awk '{ print $2 }' | tr -d '>' | tr -d '<'