Table of Contents

Mail Server#MTA (mail transfer agent)

Postfix Commands and Configuration Examples


Postfix Commands and Configuration Examples



About Postfix

http://www.postfix.org/


Commands

Service

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

Configuration

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

Queue

Commands Explanation
mailq |grep -i requests
postqueue -p |tail -n 1
Queue Numbers
mailq
postqueue -p
List Queue
Produce a traditional sendmail-style queue listing.
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
or
$ 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


Configuration

/etc/postfix/main.cf

Check Configuration file without comments

grep -Ev "^#|^$" /etc/postfix/main.cf

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 =
         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
         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 = host1.example.com
mydomain This is for a preparation for myorigin. mydomain = example.com
myorigin This is Mail From's @mydomain. myorigin = $mydomain
mynetworks mynetworks = 127.0.0.0/8, 192.168.100.0/24, 192.168.101/24
inet_interfaces inet_interfaces = all
inet_interfaces = localhost
inet_interfaces = $myhostname, localhost
relayhost relayhost = [192.168.0.100]
relayhost = [smtp.example.com]
relayhost = [smtp.gmail.com]: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

Note

postfix retry interval

Default Configuration

queue_run_delay = 100s
minimal_backoff_time = 300s
maximal_backoff_time = 4000s
maximal_queue_lifetime = 5d
bounce_queue_lifetime = 5d
300s      after 5m
600s      after 10m           300s x 2
1200s     after 20m           300s x 4
2400s     after 40m           300s x 8
4000s     after 1h 6m 40s     300s x 16 = 4800
8000s     after 2h 13m 20s    4000s + 4000s = 8000
12000s    after 3h 20m 00s    8000s + 4000s = 12000
16000s    after 4h 26m 40s   12000s + 4000s = 16000
20000s    after 5h 33m 20s
24000s    after 6h 40m 00s


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

Note

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


How to limit the amount of mail

Limit the number of sending from one client per unit time

anvil_rate_time_unit = 60s 
smtpd_client_message_rate_limit = 100

Limit the number of receiving from one client per unit time

anvil_rate_time_unit = 60s 
smtpd_client_recipient_rate_limit = 200


maillog

/var/log/maillog

Status

Status Explanation
status=sent
status=bounce
status=deferred