Skip to content

Postfix


Postfix Components
+------------------------------------------------------------------+
| |
| Postfix is modular: |
| +----------------------------------------------------------+ |
| | smtpd | SMTP server daemon | |
| | smtp | SMTP client | |
| | local | Local delivery agent | |
| | virtual | Virtual alias delivery | |
| | bounce | Delivery status notifications | |
| | cleanup | Message canonicalization | |
| | qmgr | Queue manager | |
| | pickup | Mail pickup from queue | |
| | tlsmgr | TLS management | |
| | anvil | Connection tracking | |
| | spawn | Spawn external commands | |
| +----------------------------------------------------------+ |
| |
| Mail Flow: |
| +----------------------------------------------------------+ |
| | Internet → smtpd → cleanup → qmgr → local/smtp | |
| +----------------------------------------------------------+ |
| |
+------------------------------------------------------------------+

Terminal window
# Install
sudo apt install postfix postfix-ldap postfix-pcre # Debian/Ubuntu
sudo yum install postfix # RHEL/CentOS
sudo pacman -S postfix # Arch
# Start service
sudo systemctl enable --now postfix

/etc/postfix/main.cf
# Identity
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
mydestination = $myhostname, localhost, localhost.$mydomain, $mydomain
# Network
inet_interfaces = all
inet_protocols = ipv4
mynetworks = 127.0.0.0/8, 10.0.0.0/8
mynetworks_style = subnet
# Mailbox
home_mailbox = Maildir/
mailbox_command =
# Security
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_recipient_restrictions = permit_sasl_authenticated, reject
# TLS
smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level = may
# Outbound TLS
smtp_tls_security_level = may
# Size limits
message_size_limit = 52428800 # 50MB
mailbox_size_limit = 1073741824 # 1GB
# Logging
maillog_file = /var/log/postfix.log
# Virtual domains
virtual_alias_domains = hash:/etc/postfix/virtual
virtual_alias_maps = hash:/etc/postfix/virtual
/etc/postfix/master.cf
smtp inet n - y - - smtpd
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
pickup unix n - y 60 pickup
cleanup unix n - y - cleanup
qmgr unix n - n 300 qmgr
tlsmgr unix - - y 1000? tlsmgr
rewrite unix - - y - trivial-rewrite
bounce unix - - y 0 bounce
defer unix - - y 0 bounce
trace unix - - y - bounce
verify unix - - y 1 verify
flush unix n - y 1000? flush
proxymap unix - - n - proxymap
proxywrite unix - - n - proxymap
smtp unix - - y - smtp
relay unix - - y - smtp
showq unix n - y - showq
error unix - - y - error
retry unix - - y - error
discard unix - - y - discard
lmtp unix - - y - lmtp
anvil unix - - y 1 anvil
scache unix - - y 1 scache
postlog unix n - n - postlogd

/etc/postfix/virtual
# virtual alias domains must be listed in main.cf as virtual_alias_domains
# Format: address or @domain target
user@example.com actualuser
@example.com catchall@example.com
Terminal window
# Generate database
sudo postmap /etc/postfix/virtual
sudo postfix reload

Terminal window
# Test configuration
sudo postfix check
# Start/Stop/Reload
sudo systemctl start postfix
sudo systemctl stop postfix
sudo systemctl reload postfix
sudo postfix reload
# Queue management
mailq # List queue
postqueue -p # Same as mailq
postsuper -d ALL # Delete all mail
postsuper -d <ID> # Delete specific
postsuper -r ALL # Requeue all
postsuper -r <ID> # Requeue specific
# Flush queue
postfix flush
# View mail log
tail -f /var/log/mail.log
tail -f /var/log/postfix/postfix.log

  1. What is Postfix?

    • Mail transfer agent (MTA)
  2. What are the main components?

    • smtpd, smtp, local, qmgr
  3. What is the difference between smtpd and smtp?

    • smtpd: server, smtp: client
  4. How do you check mail queue?

    • mailq or postqueue -p

Quick Reference
+------------------------------------------------------------------+
| |
| Commands: |
| +----------------------------------------------------------+ |
| | sudo postfix check | Test config | |
| | sudo postfix reload | Reload config | |
| | mailq | View queue | |
| | postsuper -d ALL | Clear queue | |
| +----------------------------------------------------------+ |
| |
| Main config: /etc/postfix/main.cf |
| Daemon config: /etc/postfix/master.cf |
| |
+------------------------------------------------------------------+