Enable TLS on a Linux Mail Server Without Breaking Delivery

Illustrated infographic summarizing: Enable TLS on a Linux Mail Server Without Breaking Delivery

By Greg Nowak. Updated 14 November 2026.

A mail server change has to survive ordinary business use: customer enquiries arriving, password resets leaving, and staff opening their inboxes. Enabling TLS means protecting those connections while keeping each workflow working.

The main decision is where to require encryption. Public SMTP delivery, authenticated sending and mailbox access need different policies. This guide covers an existing Postfix and Dovecot installation. If your only requirement is sending website notifications, consider whether a managed SMTP relay would reduce the maintenance your team owns.

Start with the applications and people affected

Record every sending application and mail client, including its hostname, port and encryption mode. Include scheduled jobs, scanners and older integrations. Give each important workflow a named tester, and agree who can roll back the change.

Save the configuration and queue status. Keep protected copies of the previous valid certificate and key files, rather than relying on renewal symlinks. Check versions before adapting the examples:

postconf mail_version
dovecot --version
Connection Port Encryption policy Acceptance check
Public incoming SMTP 25 Offer STARTTLS; allow delivery without TLS External mail arrives
Authenticated submission 587 Require STARTTLS Applications authenticate and send
Implicit TLS submission 465 TLS from connection start Clients use implicit TLS
IMAP mailbox access 993 TLS from connection start Login succeeds without warnings
Expose only the services you need, and test each one independently.

Keep public SMTP delivery compatible

For ordinary internet delivery, offer opportunistic TLS. In Postfix, smtpd_ controls incoming connections; smtp_ controls outgoing delivery:

# /etc/postfix/main.cf — Postfix 3.4 or later
smtpd_tls_security_level = may
smtp_tls_security_level = may
smtpd_tls_chain_files = /etc/postfix/mail-tls.pem

With may, encryption is optional and destination identity is not enforced. Requiring TLS globally on public port 25 can prevent legitimate delivery. Preserve stronger outbound policies already configured for a relay or particular destinations.

The combined PEM contains the private key, certificate and intermediate certificates, in that order. The Postfix TLS guide recommends this interface to avoid separate-file replacement races.

Require TLS and authentication for application sending

Adapt the existing submission entry in master.cf; retain distribution-specific service and chroot options. This example assumes Postfix 3.6 or later:

# /etc/postfix/master.cf
submission inet n - y - - smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_tls_mandatory_protocols=>=TLSv1.2
  -o smtpd_tls_auth_only=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject

This requires a working SASL backend. Enabling AUTH alone does not connect Postfix to Dovecot: verify the backend, socket path and permissions using the Postfix SASL guide. Preserve existing sender restrictions and filtering.

Port 465 needs a separate service with smtpd_tls_wrappermode=yes and equivalent authentication and relay controls. Clients must select implicit TLS.

Use Dovecot settings for your installed version

For an existing Dovecot 2.4 configuration:

ssl = required
auth_allow_cleartext = no
ssl_server_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_server_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem

Dovecot 2.3 uses different setting names and file syntax. Follow its version-specific documentation rather than treating this snippet as an upgrade procedure. The Dovecot TLS documentation also explains that standard installations read keys as root; the dovecot user does not need private-key access.

Configure clients explicitly for encryption. Server restrictions cannot prevent a misconfigured client from attempting to transmit a password before TLS. Test any retained IMAP or POP STARTTLS ports too.

Make certificate renewal deploy the certificate

Replace mail.example.com with the hostname clients actually use. The certificate must cover that name. This issuance command requires an existing HTTP server serving the specified webroot, with the challenge path publicly reachable on port 80:

sudo certbot certonly --webroot -w /var/www/html -d mail.example.com
sudo certbot certificates

Otherwise, choose an automated authenticator suited to your setup, such as a DNS plugin. Use the actual lineage path reported by Certbot.

Save the following root-owned script as /etc/letsencrypt/renewal-hooks/deploy/reload-mail. It skips unrelated renewals and replaces Postfix’s combined file atomically. Adapt paths and service names before use:

#!/bin/sh
set -eu
umask 077
lineage=/etc/letsencrypt/live/mail.example.com
[ "${RENEWED_LINEAGE:-$lineage}" = "$lineage" ] || exit 0
tmp=$(mktemp /etc/postfix/mail-tls.pem.XXXXXX)
trap 'rm -f "$tmp"' 0
cat "$lineage/privkey.pem" "$lineage/fullchain.pem" > "$tmp"
mv "$tmp" /etc/postfix/mail-tls.pem
postfix check
doveconf -n > /dev/null
systemctl reload postfix
systemctl reload dovecot

After issuance and configuration, run the script once to create the combined file and reload services. Then test renewal:

sudo chmod 700 /etc/letsencrypt/renewal-hooks/deploy/reload-mail
sudo /etc/letsencrypt/renewal-hooks/deploy/reload-mail
sudo certbot renew --dry-run --run-deploy-hooks

The last command runs applicable deploy hooks after a successful dry run, using the active certificate, as described in the Certbot renewal documentation. It can reload live services. Check the renewal scheduler and send failures to a named owner.

Prove delivery before closing the change

Check configuration, queue status and logs; some distributions write mail logs to separate files:

sudo postfix check
sudo postconf -n
sudo doveconf -n
sudo postqueue -p
sudo journalctl -u postfix -u dovecot -f

From outside the server’s network, check certificate trust and hostname identity:

openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com -verify_hostname mail.example.com -verify_return_error
openssl s_client -connect mail.example.com:993 -servername mail.example.com -verify_hostname mail.example.com -verify_return_error

Repeat the SMTP test on port 25. For port 465, omit -starttls smtp. SNI selects the hostname; hostname verification checks identity. According to the OpenSSL reference, -verify_return_error makes certificate verification failures abort the handshake.

Finally, test external inbound and outbound mail, an application notification and mailbox login. Confirm unauthenticated submission to external recipients is rejected. Compare the queue with your baseline. If a critical workflow fails, restore the saved configuration and certificate files, validate, reload and retest.

Keep monitoring the certificate served externally: successful renewal on disk does not prove deployment. Leave the team with client settings, alerts and rollback instructions.

If responsibility is split between an agency, hosting provider and internal team, Greg can help review the configuration and coordinate a tested rollout. Discuss your mail server with Greg.

Related on GrN.dk

Need help with this kind of work?

Discuss your mail server with Greg Get in touch with Greg.

Sources

Seneste artikler

En sendt faktura er ikke nødvendigvis nået frem. Få styr på leveringsstatus, systemkravene i 2027 og afgrænset AI-hjælp til fejl og opfølgning i økonomiafdelingen.

Rækker jeres ChatGPT-licens til weboversættelser? Få overblik over API-kreditter, adgang og en WordPress-proces fra godkendt dansk tekst til oversættelseskladder.

Få styr på manglende bilag med et afgrænset AI-flow, der sorterer svar, koordinerer påmindelser og giver bogholderen en overskuelig liste til opfølgning.

Lad AI skrive kampagneudkast til Black Friday ud fra godkendte produktdata. Få styr på priser, modtagere og godkendelse, før Mailchimp-kladden bliver sendt.

Få tilbudsmails fra Outlook ind i CRM med AI. Afklar felter, dubletter og sælgeransvar, og mål i en pilot, om løsningen sparer tid og får flere forespørgsler fulgt op.

Gør månedsrapporten lettere at gentage med AI til Excel, Python og faste kontroller. Få styr på import, fejllister og afstemning, så tallene kan efterprøves.

Få godkendte timer fra Clockify med på fakturakladder i Dinero. AI skriver ydelsesbeskrivelser, mens faste regler styrer beløb, godkendelse og genkørsler.

Lad AI kundeservice hente ordrestatus fra Shopify og Shipmondo. Se, hvordan I afgrænser opgaven, kontrollerer kundens identitet og sender usikre sager videre.

Når kunden beder om indsigt, kan AI hjælpe med at samle materiale fra WordPress og Microsoft 365. Se, hvordan I holder styr på datakilder, ansvar og kontrol.

Når en ingrediens ændres, kan menukortet kræve rettelser, selv om opskriftsdatoen står stille. Sådan kan AI hjælpe med gennemgang og godkendelse i WordPress.