cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

middleware:mail:postfix:index.html



Mail Server#MTA (mail transfer agent)

Postfix Configuration Examples

About Postfix

Commands

Service

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

Configuration

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

Queue

Commands Explanation
mailq
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
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


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


TIPS

Relay mail addressed to a specific domain to another server

/etc/postfix/main.cf
relay_domains = example.com, example.jp
transport_maps = hash:/etc/postfix/transport
/etc/postfix/transport
example.com     smtp:[x.x.x.x]
example.jp      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

/etc/postfix/main.cf
sender_dependent_default_transport_maps = hash:/etc/postfix/sender_dependent_transport
/etc/postfix/sender_dependent_transport
@example.com        stmp:[x.x.x.x]:25
@sub.example.com    stmp:[x.x.x.x]:25


2. sender_dependent_relayhost_maps

Overridden in transport table

/etc/postfix/main.cf
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_dependent_relayhost
/etc/postfix/sender_dependent_relayhost
@example.com        [x.x.x.x]:25
@sub.example.com    [x.x.x.x]:25


maillog

/var/log/maillog

Status

Status Explanation
status=sent
status=bounce
status=deferred



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

Page Tools