ZhoubaWiki:PostfixTips
This page contain some usefull commands and tips for using Postfix.
Certificate problems
If postfix can't validate email certificiates mail log will be full of message like these
certificate verification failed for gmail-smtp-in.l.google.com[74.125.196.26]:25: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Check if certificates are installed and updated in /etc/ssl/certs/
, if they are set
path to them manually by adding line to /etc/postfix/main.cf
.
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Checking mail queue
To check current mail queue use:
postqueue -p | tail -n 1 | cut -d' ' -f5
Searching and restoring emails in SPAM folder
Default spam folder is /var/lib/amavis/virusmails
.
To find name of spam email containing KEYWORD:
cd /var/lib/amavis/virusmails find . -name "*spam*.gz" -exec zgrep -l 'KEYWORD' {} \;| cut -c 3-
To copy spam to original recipient mailbox, EMAILNAME should be relative to spam folder.
amavisd-release EMAILNAME
To release found mail:
find . -name "*spam*.gz" -exec zgrep -l 'KEYWORD' {} \;| cut -c 3- | xargs -L 1 amavisd-release
How to move Postfix mail queue
This document describes how to move Postfix mail queue from one server to another without downtime.
- ServerA - server with queue we want to move
- ServerB - server with install working Postfix
Before start, check both ServerA and ServerB hold queue /var/spool/postfix/hold
.
Any email in hold queue will be send. In case there are emails in hold that should not be send move them out of hold folder.
ServerA
Move all waiting emails to hold queue.
postsuper -h ALL
Tar hold folder and copy it to ServerB.
tar -zcvf postfixhold.tar.gz /var/spool/postfix/hold scp postfixhold.tar.gz user@ServerB:/home/user/
ServerB
Untar to /var/spool/postfix/hold
.
tar -C / -zxvf postfixhold.tar.gz
Number of added hold emails should increase queued emails (Protip: run this command before untaring hold emails)
postqueue -p | tail -n 1 | cut -d' ' -f5
Put emails from hold to deferred queue.
postsuper -H ALL
Manual recommends releasing emails near maximal wait time directly to active queue.
postsuper -r ALL hold
ServerA
Now remove whole hold queue on ServerA.
postsuper -d ALL hold
Log statistics
One of tools for generating statistics from email logs is Pflogsumm
.
Installation
sudo curl -O http://jimsun.linxnet.com/downloads/pflogsumm-1.1.3.tar.gz sudo tar -xzf pflogsumm-1.1.3.tar.gz
Usage
./pflogsumm.pl /var/log/email.log > report.txt
Getting message id
Getting message id from mail where argo or bugweis is mentioned
mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($0 ~ /(argo22\.)|(bugweis\.)/) print $1 }' | tr -d '*!'
Release multiple emails from hold
Can be connected wtih 'Getting message id' command and output piped directly to postsuer. -H - will read message ID from input.
cat ouremails_ID.txt | postsuper -H -
Removing emails for whole domain
First be sure you know what are you doing, this will DELETE most of emails in standard email directory! Running script at wrong place can cripple the company!
Backup vhole email directory (/var/vmail/DOMAIN/).
Run following script, make sure initial change directory is set correctly
cd /var/vmail/DOMAIN; for DIR in `ls -l`; do rm -vf $DIR/Maildir/cur/*;rm -vf $DIR/Maildir/new/*;rm -vf $DIR/Maildir/.*/cur/*;rm -vf $DIR/Maildir/.*/new/*; done;