Configure SSL for SMTP
SMTP was designed without encryption. TLS was added later, and it arrived in two forms: STARTTLS, which upgrades an existing plain connection, and implicit TLS, where the connection is encrypted from the first byte. Knowing which port uses which form saves a lot of confusion when configuring servers and mail clients.
SMTP SSL: the ports at a glance
| Port | Purpose | TLS style | Should TLS be required? |
|---|---|---|---|
| 25 | Server-to-server delivery | STARTTLS, opportunistic | Usually optional, unless agreed per domain |
| 587 | Mail submission from users | STARTTLS | Yes |
| 465 | Mail submission from users | Implicit TLS | Yes |
RFC 8314 recommends implicit TLS for submission and also describes port 587 with STARTTLS as acceptable. In practice, offer 587 and 465 and require encryption on both. Port 25 stays opportunistic because many sending servers cannot do TLS, and refusing them would lose mail.
Step 1: Certificate requirements
The certificate must cover the hostname that clients enter in their mail settings and that your MX record points at. Intermediate certificates must be included. For issuing one for free, see Certbot basics. A wider walkthrough for the whole mail stack is in Install SSL on a Mail Server.
SMTP SSL, step 2: Postfix settings
smtpd_tls_cert_file = /etc/ssl/mail/fullchain.pem
smtpd_tls_key_file = /etc/ssl/mail/privkey.pem
smtpd_tls_security_level = may
smtpd_tls_auth_only = yes
smtpd_tls_protocols = >=TLSv1.2
smtp_tls_security_level = maysmtpd_tls_auth_only = yes stops Postfix from offering authentication until the session is encrypted, so passwords never travel in the clear. The smtp_tls_* lines control outbound connections from your server to others.
Step 3: Enable submission in master.cf
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=
permit_sasl_authenticated,reject
smtps inet n - y - - smtpd
-o syslog_name=postfix/smtps
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_recipient_restrictions=
permit_sasl_authenticated,rejectThe first service is port 587 with required STARTTLS. The second is port 465 with implicit TLS (wrappermode). Make sure your firewall allows the ports you enable and that SASL authentication through Dovecot or another backend is configured. Run postfix check and then postfix reload.
Step 4: Test with OpenSSL
# STARTTLS on submission
openssl s_client -starttls smtp \
-connect mail.example.com:587 -servername mail.example.com
# Implicit TLS on 465
openssl s_client -connect mail.example.com:465 \
-servername mail.example.comLook for Verification: OK and the expected certificate subject. After the handshake, type EHLO test and check that AUTH appears only now, not before encryption. See testing SSL configuration with OpenSSL for how to read the rest of the output.
Step 5: Consider MTA-STS and DANE
Opportunistic TLS on port 25 can be downgraded by an attacker who strips the STARTTLS offer. Two standards address this for server-to-server mail. MTA-STS publishes a policy over HTTPS that tells senders to require TLS and validate your certificate. DANE publishes certificate information in DNSSEC-signed DNS records. Both need careful setup, and a mistake can cause mail to be rejected, so test in a reporting or testing mode first and read the specifications or your software's docs.
Step 6: Renewals
Postfix keeps the certificate it loaded until it reloads. After renewal run postfix reload from a deploy hook, as shown in automating renewal with Certbot.
Client-side notes
If you are sending mail from an application, use port 587 with STARTTLS or port 465 with implicit TLS, and leave certificate verification on. Many libraries use the setting name "SSL" for implicit TLS and "TLS" for STARTTLS, which is confusing; read your library docs. Never disable verification to work around a name mismatch, because it removes the protection you set up.
Troubleshooting
- Clients get a name mismatch: they connect to a name not in the certificate. Use the mail hostname, not the bare domain.
- Authentication is offered before TLS: check
smtpd_tls_auth_only. - Port 465 does not answer: the smtps service is not enabled in
master.cf, or the firewall blocks it. - Some hosts block port 25 outbound: a provider policy. Ask the provider or relay through port 587.
Related reading: SSL on a mail server, SPF and DMARC records and SSL for MySQL.
Frequently Asked Questions
Which port should mail clients use?
587 with STARTTLS, or 465 with implicit TLS. Port 25 is for server-to-server mail and is often blocked by hosts and ISPs.
Does SMTP TLS need a special certificate?
No. The certificate has to carry the mail hostname, and clients have to verify it.
Why does mail still arrive unencrypted?
Port 25 is opportunistic: if the other server offers no STARTTLS, the message goes in clear text. MTA-STS and DANE are what close that.
✅ Post-Installation Verification & SEO Checklist
After applying the steps above, run through this 5-point checklist to prevent browser warnings and protect your Google SEO rankings:
- Verify full CA chain trust and TLS 1.3 support using our Live SSL Checker.
- Scan for Mixed Content HTTP links and check HSTS/CSP headers on Security Headers Checker.
- Enforce a permanent 301 HTTP-to-HTTPS redirect with our HTTPS Redirect Generator.
- Confirm both root and
wwwversions resolve cleanly to one canonical HTTPS URL. - Verify your HTTPS property and
sitemap.xmlinside Google Search Console and Bing Webmaster Tools.