Archive

Archive for the ‘Postfix’ Category

Postfix administration tips

May 28, 2015 Leave a comment

 
 
1) Queue count
 

postqueue  -p|awk 'NF==7 && $1 ~ /^[A-Z0-9a-z]/{print $1}'|wc -l

 
2) Top 10 senders
 

postqueue -p|awk 'NF==7{print $NF}'|sort|uniq -c|sort -nr|head

 
3) List out emails send by given email address,
 

read -p "Email: " EMAIL;postqueue -p|awk -v email=${EMAIL} '$NF ~ email{if(NF>6)print $0}'|head

 
4) Delete all emails send by given email address,
 

read -p "Email: " EMAIL; postqueue -p|awk -v email=${EMAIL} '$NF ~ email{if(NF>6){split($1,a,"*");system("postsuper -d "a[1]);}}'

 
5) Extract headers of all emails in queue to file “list.txt” along with the mail id at the top. This could be later used for performing various pattern analysis based on header.
 

:>list.txt
queuelist=$(postqueue  -p|awk 'NF==7 && $1 ~ /^[A-Z0-9a-z]/{print $1}')
for i in $queuelist;do 
j=$(echo ${i}|tr -d '*')
echo -n "${j} " >> list.txt
postcat -q ${j} 2>/dev/null|sed -n '/^message_size:/,/^Content-/p' >> list.txt
done 

 
6) Find out for which email id is MAILER-DAEMON bounces are coming. There is an option to remove the MAILER-DAEMON bounces for a specific email id as well. Useful while troubleshooting increased bounces in queue.
 

:>/tmp/mailer-daemon.txt
:>/tmp/mailer-daemon_details.txt

EMAIL="MAILER-DAEMON";postqueue -p|awk -v email=${EMAIL} '$NF ~ email{if(NF>6){split($1,a,"!");print a[1]}}' > /tmp/mailer-daemon.txt
for i in `cat /tmp/mailer-daemon.txt`;do  postcat -q $i |sed -nr 's/^recipient:\s(.*@.*)$/'${i}' \1/p'; done >> /tmp/mailer-daemon_details.txt
awk '{print $2}' /tmp/mailer-daemon_details.txt|sort|uniq -c|sort -nr|head
read -p "Email: " EMAIL;awk -v email=${EMAIL} '$2 ~ email{system("postsuper -d " $1)}' /tmp/mailer-daemon_details.txt 

 
7) Put email “on hold” queue so that no attempt is made to deliver it,
 

postsuper -h MSG_QUEUEID

 
8) Requeue the message with the named queue ID,
 

postsuper -r MSG_QUEUEID

 
9) Show postfix deferred queue message distribution in time based on sender domain,
 

qshape -s deferred

 

Categories: Mail, Postfix