Useful Posfix Commands Cheat Sheet

PowerADM.com / Linux / Useful Posfix Commands Cheat Sheet

This cheat sheet is a collection of useful Postfix commands that I use frequently. The following five console commands are mainly used to manage postfix:

  • mailq
  • postqueue
  • postcat
  • postsuper
  • postconf

List the current Postfix queue:

$ mailq

or:

$ postqueue –p
You can view the contents of the different queues in this way:

$ find /var/spool/postfix/deferred -type f | wc -l
$ find /var/spool/postfix/active -type f | wc -l
$ find /var/spool/postfix/incoming -type f | wc -l
$ find /var/spool/postfix/defer -type f | wc -l

Show the number of messages in the queue:

$ mailq | grep Request

Or:

$ mailq | wc -l

The number of email messages in the queue for a specific address:

$ mailq | grep info@poweradm.com | wc –l

Display information about a specific message in the queue (you can find the messageID in the output of the mailq command):

$ postcat -q messageID

useful postfix commands

Save email to file:

$ postcat -vq  messageID > out_message.txt

Rejected email statistics:

$ qshape deferred

See a list of the most active senders:

$ mailq|grep ^[A-F0-9] |cut -c 42-80| sort | uniq -c| sort -n

Get the send queue for a specific domain name:

$ mailq | grep gmail

Or

$ postqueue -p | grep gmail

Force Postfix to send e-mail from the mail queue:

$ mailq -q

Or:

$ postqueue –f

Force send to a domain:

$ postqueue -s example.com

Force send by messageID:

$ postqueue -i messageID

or:

$ postsuper -r messageID

Soft queue restart:

$ postsuper -r ALL

Full queue restart:

$ postfix stop
$ postsuper -r ALL
$ postfix start

Remove all messages from the queue:

$ postsuper -d ALL

Clear only the deferred queue:

$ postsuper -d deferred

Delete e-mail item by messageID:

$ postsuper -d messageID

Remove item from a queue by the sender:

$ postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /spam@email\.com/ { print $1 }' | tr -d '*!' | postsuper -d

View current Postfix settings:

$ postconf

Get a specific parameter value:

$ postconf | grep smtp_helo_timeout

Change the value of the postfix parameter without rebooting:

$ postconf -e 'message_size_limit = 20480000'

Check the syntax of the Postfix configuration files:

$ postfix check

Get Postfix default settings:

$ postconf -d

Show only the configured settings that are different from the default settings:

$ postconf -n
Leave a Reply

Your email address will not be published. Required fields are marked *