To secure a mail server with a Lets Encrypt certificate, request a certificate for your mail hostname with Certbot, point Postfix and Dovecot at the certificate files, require TLS for logins and reload both services after every renewal. A mail server TLS certificate encrypts passwords and messages in transit and lets mail clients trust your server.
This article continues the Postfix and Dovecot setup. The hostname is mail.example.com. Use your own name, and make sure its DNS A record already points to the server.
Without TLS, IMAP and SMTP logins can send passwords in readable form, and anyone on the path can read your mail. A certificate that matches the server name also lets clients check they are talking to the right machine. Three connections need TLS:
| Connection | Port | Where it is configured |
|---|---|---|
| Mail clients reading mail (IMAPS) | 993 | Dovecot |
| Mail clients sending mail (submission) | 587 (STARTTLS) or 465 (implicit TLS) | Postfix |
| Server to server delivery | 25 (opportunistic STARTTLS) | Postfix |
Lets Encrypt is a free certificate authority that issues short-lived certificates, currently valid for 90 days, and supports automatic renewal. The certificate must be for the hostname clients connect to (mail.example.com), not only the bare domain.
Certbot proves you control the domain, then saves the certificate. For a mail server that has no web server, the standalone method is the simplest. It temporarily listens on port 80, so open it in the firewall.
If a web server such as nginx already uses port 80, use the webroot method (--webroot -w /var/www/html) or the DNS challenge instead. The DNS method needs no open port and works with a DNS provider plugin.
Two files matter: fullchain.pem (your certificate plus intermediates) and privkey.pem (the private key). Always use the files in the live/ folder, which are symlinks to the newest version, so renewals are picked up automatically.
Set the paths and the security level with postconf.
The smtpd_tls_chain_files parameter exists in Postfix 3.4 and later and takes the private key first, then the certificate chain. Older versions use smtpd_tls_cert_file and smtpd_tls_key_file instead. Setting smtpd_tls_auth_only = yes stops Postfix offering password login until the connection is encrypted.
Port 25 uses may (opportunistic encryption) because other servers may not support TLS, and forcing it would drop their mail. Authenticated submission is different, so enable a dedicated submission service in /etc/postfix/master.cf that insists on TLS.
Reload Postfix, and open port 587 in the firewall.
Edit /etc/dovecot/conf.d/10-ssl.conf.
The leading < tells Dovecot to read the file contents, so do not omit it. ssl = required means clients cannot log in over plain connections. Dovecot 2.4 renames some of these settings (for example the certificate and key move to named ssl_server blocks), so run doveconf -n and check the 2.4 documentation if you are on that release.
Lets Encrypt certificates expire after 90 days, and Certbot installs a systemd timer that renews them. The mail services will keep using the old certificate in memory until reloaded, so add a deploy hook that runs after each successful renewal.
The dry run exercises the renewal process without changing anything. If it fails, the real renewal will too, usually because port 80 is closed or DNS is wrong. Check the timer with systemctl list-timers | grep certbot.
Check each service from outside the server.
A verify code of 0 means the chain is valid. A mail client should connect without a certificate warning. For a fuller report, run an online checker against your domain, and read /var/log/mail.log for lines such as TLS connection established from that show which protocol and cipher senders used.
Yes, if the certificate covers the hostname used by each service, or you request a certificate with several -d names. Many people keep a separate certificate for mail.example.com so a web server change cannot break mail.
Postfix and Dovecot only read the certificate when they start or reload. Add the deploy hook shown above, or reload both services after renewal.
No. Servers that cannot do TLS would be unable to deliver mail to you. Use opportunistic TLS on port 25 and mandatory TLS on submission and IMAP.
For testing only. Clients will warn about it and many will refuse to connect, so use a certificate from a trusted authority in real use.
Get a certificate for the mail hostname with Certbot, then point Postfix and Dovecot at fullchain.pem and privkey.pem. Require TLS for authentication, submission and IMAP, keep opportunistic TLS on port 25, and automate reloads with a deploy hook. Verify with openssl s_client and certbot renew --dry-run. Next you will sign outgoing mail so receivers can trust it.