Skip to content

SMTP TLS with Postfix

Use a publicly trusted certificate for the actual mailhost.

Setup

Prepare your values and Debian packages. Commands use your domain and files.

First publish the MAILHOST A record and make HTTP port 80 reachable for ACME. With an existing webserver, use its webroot challenge instead of stopping it. On a fresh host without an HTTP service:

Public ACME issuance
. /root/mailserver.env
certbot certonly --standalone --preferred-challenges http --agree-tos \
  --non-interactive --email "$REPORT_MAILBOX" -d "$MAILHOST"

Then configure Postfix. The certificate paths must exist. Do not use self-signed laboratory certificates for public operation.

set -euo pipefail
. /root/mailserver.env
test -s "/etc/letsencrypt/live/$MAILHOST/fullchain.pem"
test -s "/etc/letsencrypt/live/$MAILHOST/privkey.pem"
postconf -e "smtpd_tls_cert_file=/etc/letsencrypt/live/$MAILHOST/fullchain.pem"
postconf -e "smtpd_tls_key_file=/etc/letsencrypt/live/$MAILHOST/privkey.pem"
postconf -e 'smtpd_tls_security_level=may' 'smtp_tls_security_level=may'
postconf -e 'smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt'
postconf -e 'smtpd_tls_mandatory_protocols=>=TLSv1.2' 'smtp_tls_mandatory_protocols=>=TLSv1.2'
install -d /etc/letsencrypt/renewal-hooks/deploy
cat > /etc/letsencrypt/renewal-hooks/deploy/postfix-reload <<'EOF'
#!/bin/sh
set -eu
postfix check
systemctl reload postfix
EOF
chmod 0755 /etc/letsencrypt/renewal-hooks/deploy/postfix-reload
postfix check
systemctl reload postfix

If you publish DANE/TLSA, configure key reuse and TLSA verification in the deploy process before the first renewal. This basic reload hook alone does not prevent a TLSA key mismatch. Running the block above again also resets outgoing TLS to may; restore any existing DANE configuration according to the DANE guide afterwards.

Test

set -euo pipefail
. /root/mailserver.env
timeout 15 openssl s_client -starttls smtp -connect 127.0.0.1:25 \
  -servername "$MAILHOST" -verify_hostname "$MAILHOST" -verify_return_error \
  -CAfile /etc/ssl/certs/ca-certificates.crt </dev/null

From an external system, also run the same command with -connect "$MAILHOST:25". Check certbot renew --dry-run against the ACME staging environment.

Expected: successful certificate verification and STARTTLS availability. Port 25 uses opportunistic may to retain interoperability with legitimate external MTAs. Configure port 587, SMTP AUTH and required TLS separately for user submission; this recipe does not configure user login.