Commands to check spam in Ubuntu with Postfix

Read More

mailq   Watch the mail queue
postfix -f  Flush the mail queue
postsuper -d ALL To remove all mails from the queue
postsuper -d deferred deferred To remove all mails in the deferred queue
find /var/spool/postfix/deferred -type f | wc -l    To know the number of messages sitting in the deferred queue
postcat -vq ID To view message content in queue with ID
qshape active Display number of emails being sent to each domain and how long they have been in the active queue
qshape deferred Display differed queue
tail -f /var/log/mail.log View the log in realtime
To check mail log for sent messages
cat /var/log/mail.log |grep -v "relay=local" |grep "relay=" |grep "status=sent"

To get statistics, install a script:

tar -zxf pflogsumm-1.1.1.tar.gz
chown root:root pflogsumm-1.1.1
cd pflogsumm-1.1.1
cat /var/log/mail.log | ./

You can move to /usr/local/bin

To send a weekly report

Create /etc/cron.weekly/mailreport
# mailreport cron weekly
MailSubject="Email report $(date +%d-%m-%Y)"
cat /var/log/mail.log | /usr/local/bin/ | /usr/bin/mailx -s "$MailSubject"
exit 0

Change file permissions to read, execute
chown root:root /etc/cron.weekly/mailreport
chmod 755 /etc/cron.weekly/mailreport

Report today problems

pflogsumm -d today /var/log/mail.log --problems_first

Get permanent errors hard bounces
grep " dsn=5." /var/log/mail.log | grep -o -P " to=<(.+?)>" | sort | uniq -c
Get soft bounces
They start with 4…
grep " dsn=4." /var/log/mail.log | grep -o -P " to=<(.+?)>" | sort | uniq -c

To check user logins

grep "sasl_method=LOGIN" /var/log/mail.log