Postfix

# view mailqueue
mailq
 
# view email count in mailqueue
mailq | egrep '^--'
 
# delete single mail from queue
postsuper -d Queue_ID
 
# delete all mailqueues
postsuper -d ALL
 
# send waiting messages
postfix flush
 
# delete duplicate mail
mailq | awk 'BEGIN { RS = "" } / foo\.bar@example\.com$/ { print $1 }' | tail -1 | postsuper -d -
 
# statistic
apt-get install pflogsumm
pflogsumm --detail 0 /var/log/mail.log
 
# view spam
grep "policyd-weight.*action=" /var/log/mail.log | grep -v PREPEND | grep mike
 
# find mails bigger then 50mb
find /home/ -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
 
# blacklists
http://zy0.de/q/YOUR_MAILSERVER_IP
http://www.dnsbl.info/dnsbl-database-check.php
 
# test
echo "USER: ${USER}" | mail -s "TEST from ${HOSTNAME}" mail@example.com
 
# configure postfix virtual alias table
vi /etc/postfix/virtual
postmap /etc/postfix/virtual
service postfix reload
 
# configure mail aliases
/etc/aliases
newaliases
service postfix reload
 
# Show mail content
postcat -vq C6024306280
 
# Rewrite sender
cat <<EOF>> /etc/postfix/generic
@example.com foo@bar.com
root foo@bar.com
EOF
postmap /etc/postfix/generic
 
postconf -e 'smtp_generic_maps = hash:/etc/postfix/generic'
service postfix restart
 
# sasl authentification
#apt-get install -y libsasl2-modules
 
cat <<EOF> /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 foo@gmail.com:pass1234
EOF
 
chmod 600 /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
 
postconf -e 'relayhost = [smtp.gmail.com]:587'
postconf -e 'smtp_sasl_auth_enable = yes'
postconf -e 'smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd'
postconf -e 'smtp_tls_security_level = may'
postconf -e 'smtp_sasl_security_options = noanonymous'
 
service postfix restart
 
# maps
/^(.*)@(.*)\.local\.lan$/     ${1}.${2}@domain.tld
 
# Links
http://www.buildcube.com/tech_blog/2012/07/15/inspecting-postfixs-email-queue/
http://www.linuxlasse.net/linux/howtos/Blacklist_and_Whitelist_with_Postfix - Blacklist & Whitelist with Postfix
http://www.huschi.net/4_277_de-postfix-mail-queue-bearbeiten.html
http://zy0.de/
http://www.dnsbl.info/dnsbl-database-check.php
http://www.cyberciti.biz/faq/howto-blacklist-reject-sender-email-address/
http://necrux.com/smtp-sender-dependent-sasl-authentication-in-postfix/
 
# Spam list check / remova
https://www.rackaid.com/blog/spam-blacklist-removal/