List of helpfull command that used to help me when maintaining Postfix mailserver.
Hemat Pangkal Kaya
Insignificant one
List mail queue and MAIL_ID’s, list mail queuepostqueue -p
mailq
Check the postfix versionpostconf mail_version
Get default value set on the postfix configpostconf -d
Get non default value set on the postfix configpostconf -n
Flush the mail queuwpostfix flush
Force to send the queue postqueue -f
Process all emails stuck in the queuepostsuper -r ALL && postqueue -f
Read email from mail queuepostcat -q MAIL_ID
Remove certain mail from mail queuepostsuper -d MAIL_ID
Remove all mail queuepostsuper -d ALL
Fast method to remove mail from queuefind /var/spool/postfix/deferred/ -type f | xargs -n1 basename | xargs -n1 postsuper -d
Remove all the deferred mail in queuepostsuper -d ALL deferred
Sorting email with “from address” filterpostqueue -p | awk '/^[0-9,A-F]/ {print $7}' | sort | uniq -c | sort -n
Remove all email that sent to [email protected]postqueue -p|grep '^[A-Z0-9]'|grep [email protected]|cut -f1 -d' '|tr -d \*|postsuper -d -
Remove all email sent from [email protected]postqueue -p|awk '/^[0-9,A-F].*[email protected] / {print $1}'|cut -d '!' -f 1|postsuper -d -
Remove all email sent from the dom.ainpostqueue -p | grep '^[A-Z0-9]'|grep @dom.ain|cut -f1 -d' ' |tr -d \*|postsuper -d -
Mail queue stats shortpostqueue -p | tail -n 1
Number of emails in Mail queuepostqueue -p | grep -c "^[A-Z0-9]"
Fast count of emails in mail queuefind /var/spool/postfix/deferred -type f | wc -l
Watch Log Livetail -f /var/log/maillog
Count and sort success pop3/imap logins
grep "\-login" /var/log/dovecot-info.log |grep "Login:"|awk {'print $7'}|sort|uniq -c|sort -n
Count and sort success SMTP postfix logins. This is usefull when you want to track a compromised account.
grep -i "sasl_username" /var/log/maillog |awk {'print $9'}|sort|uniq -c|sort -n
Count and sort success SMTP postfix logins on exact date “May 18”
grep -i "sasl_username" /var/log/maillog |grep "May 18"|awk {'print $9'}|sort|uniq -c|sort -n
Analyze Postfix Logs
pflogsumm /var/log/maillog | less
You may need to install the pflogsumm package first.