Set up Postfix with TLS

Postfix has two TLS sides: smtpd for incoming connections and smtp for sending to other servers. Both need their own settings, and port 25 behaves differently from 587.

Incoming: smtpd (main.cf)

# certificate: key first, then certificate with chain (Postfix 3.4+)
smtpd_tls_chain_files =
    /etc/letsencrypt/live/mail.example.com/privkey.pem,
    /etc/letsencrypt/live/mail.example.com/fullchain.pem

smtpd_tls_security_level = may
smtpd_tls_auth_only      = yes
smtpd_tls_loglevel       = 1
smtpd_tls_mandatory_protocols = >=TLSv1.2   # syntax from Postfix 3.6

Submission: 587 and 465 (master.cf)

Mail programs get their own ports with mandatory TLS and authentication:

submission inet n       -       y       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

submissions inet n      -       y       -       -       smtpd
  -o syslog_name=postfix/submissions
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject

587 works with STARTTLS, 465 with direct TLS (smtpd_tls_wrappermode). Mixing the methods up in the mail program gives “wrong version number”.

Outgoing: smtp (main.cf)

smtp_tls_security_level = may
smtp_tls_loglevel       = 1
smtp_tls_CApath         = /etc/ssl/certs

may encrypts whenever the target server offers STARTTLS. Only DANE or MTA-STS protect against attackers who strip STARTTLS.

DANE for sending

With a DNSSEC-validating resolver on the server (e.g. unbound), Postfix checks the recipients’ TLSA records:

smtp_dns_support_level  = dnssec
smtp_tls_security_level = dane

For your incoming server’s own TLSA records, create and check the hash with the CAA & DANE tool. Important: when changing certificates, publish the new TLSA record beforehand or use a record for the CA (2 1 1).

Test

sudo postfix check && sudo postfix reload

openssl s_client -starttls smtp -connect mail.example.com:25 -servername mail.example.com -brief </dev/null
posttls-finger -c mail.example.com      # Postfix's own test tool

grep "TLS connection established" /var/log/mail.log | tail

The log says Trusted TLS connection established when the peer certificate was verified, and Anonymous or Untrusted for opportunistic TLS. The mail server check shows the overall state from outside, including MTA-STS and DANE. For Let's Encrypt to take effect: --deploy-hook "systemctl reload postfix" with certbot.

FAQ

Is a self-signed certificate enough for port 25?

Most servers accept it for opportunistic TLS. With MTA-STS or for clean reports you need a publicly valid certificate for the MX name. Let's Encrypt is free.

Should I disable TLS 1.0 on port 25?

With smtpd_tls_mandatory_protocols the limit only applies to mandatory TLS (587, 465). On port 25 a very old sender would otherwise fall back to plain text. That is rare today; it remains a trade-off.

Do I need a separate certificate for Dovecot?

No, Dovecot can use the same files (ssl_cert and ssl_key with a leading <). Reload Dovecot too on renewal.

Sources and documentation