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 <> /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 < /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

# network_table
# /usr/local/etc/postfix/network_table.cidr
# /etc/postfix/main.cf
mynetworks = hash:/etc/postfix/network_table

/etc/postfix/network_table
10.0.0.2 OK
10.100.200.0/24 OK

postmap /etc/postfix/network_table

maps
/^(.*)@(.*)\.local\.lan$/ ${1}.${2}@domain.tld

# get stress settings
postconf -d | grep stress

# Veryfy certificate / TLS
https://www.checktls.com/TestReceiver

# 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/
https://mxtoolbox.com/SuperTool.aspx