- Cheat Sheet and Example is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools






Mail Server#MTA (mail transfer agent)

Postfix Configuration Examples

About Postfix



Commands Explanation
service postfix status
/etc/init.d/postfix status
update-alternatives --config mta
postalias /etc/postfix/aliases


Commands Explanation
postconf list all configuration
postconf -n Display only parameters different from default
postconf -d list default configuraiton


Commands Explanation
postqueue -p
List Queue
Produce a traditional sendmail-style queue listing.
mailq |grep -i requests Queue Numbers
postqueue -f Flush the queue: attempt to deliver all queued mail.
postcat -q QueueID show Postfix queue file contents
postsuper -d QueueID Delete one message with the named queue ID from the named mail queue(s)
postsuper -d ALL “-d All” to remove all messages
List up All Queue's Subject and Mails
$ postqueue -p |awk {'print $1'} | egrep -v "connect|@|-|^$" > tmp.txt
$ for i in `cat tmp.txt` ; do postcat -q $i |grep ^Subject ; done
$ for i in `cat queue.txt` ; do postcat -q $i ; done
Reading Japanese Queue Mails
$ postqueue -p |awk {'print $1'} | egrep -v "connect|@|-|^$" > tmp.txt

## mail header and body
$ for i in `cat queue.txt` ; do postcat -q $i | nkf -m ; done
$ for i in `cat queue.txt` ; do postcat -q $i | iconv -f ISO-2022-JP -t UTF-8 ; done

## Subject
$ for i in `cat queue.txt` ; do  postcat -q $i |grep ISO-2022-JP | grep -v Content-Type |nkf -w ; done



Check Configuration file without comments

grep -Ev "^#|^$" /etc/postfix/

Defautl Configuration (CentOS)

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
inet_interfaces = localhost
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
         ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

Configuration of send mail

myhostname This is written in mail header. myhostname =
mydomain This is for a preparation for myorigin. mydomain =
myorigin This is Mail From's @mydomain. myorigin = $mydomain
mynetworks mynetworks =,, 192.168.101/24
inet_interfaces inet_interfaces = all
inet_interfaces = localhost
inet_interfaces = $myhostname, localhost
relayhost relayhost = []
relayhost = []
relayhost = []:587
allow_min_user Deliver mail starting with '-' allow_min_user = yes
smtp_host_lookup Use /etc/hosts for test environment. smtp_host_lookup = native

Configuration of recive mail

mydestination mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox home_mailbox = Maildir/
mailbox_size_limit mailbox_size_limit = 102400000 #100M : 102,400,000
message_size_limit message_size_limit = 10240000 #10M : 10,240,000


How to create automatically a Maildir directory when useradd.
mkdir -p /etc/skel/Maildir/new
mkdir -p /etc/skel/Maildir/cur
mkdir -p /etc/skel/Maildir/tmp
chown -R 700 /etc/skel/Maildir/
useradd  testuser
passwd testuser
ls -al /home/testuser

Configuration of Security

disable_vrfy_command disable_vrfy_command = yes #disable
smtpd_banner diable postfix version

you can check with 'telnet x.x.x.x 25'.
smtpd_banner = $myhostname ESMTP unknown
smtpd_banner = $myhostname ESMTP $mail_name #$mail_name is postfix


Relay mail addressed to a specific domain to another server

relay_domains =,
transport_maps = hash:/etc/postfix/transport
/etc/postfix/transport     smtp:[x.x.x.x]      smtp:[x.x.x.x]
Reflect settings
postmap  hash:/etc/postfix/transport
systemctl reload postfix

Change delivery destination by sender(From:)

You can use sender_dependent_default_transport_maps or sender_dependent_relayhost_maps.

1. sender_dependent_default_transport_maps

sender_dependent_default_transport_maps = hash:/etc/postfix/sender_dependent_transport
/etc/postfix/sender_dependent_transport        stmp:[x.x.x.x]:25    stmp:[x.x.x.x]:25

2. sender_dependent_relayhost_maps

Overridden in transport table

sender_dependent_relayhost_maps = hash:/etc/postfix/sender_dependent_relayhost
/etc/postfix/sender_dependent_relayhost        [x.x.x.x]:25    [x.x.x.x]:25




Status Explanation

middleware/mail/postfix/index.html.txt · Last modified: 2020/03/11 by admin

Page Tools