Skip to content

How to Fix Postfix TLS Configuration Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Postfix TLS Configuration Error. We cover key concepts, practical examples, and best practices.

Postfix returns TLS handshake failed or clients see STARTTLS not available when connecting — the TLS certificate is missing, permissions are wrong, or the TLS configuration is incomplete.

The Problem

$ openssl s_client -connect mail.example.com:587 -starttls smtp
CONNECTED(00000003)
14000000:error:1408F10B:SSL routines:ssl3_get_record:wrong version number

Step-by-Step Fix

Step 1: Configure TLS in main.cf

# /etc/postfix/main.cf
smtpd_tls_cert_file = /etc/ssl/certs/mail.example.com.crt
smtpd_tls_key_file = /etc/ssl/private/mail.example.com.key
smtpd_tls_security_level = may
smtpd_tls_protocols = TLSv1.2 TLSv1.3

smtp_tls_security_level = may
smtp_tls_loglevel = 1

Step 2: Set correct permissions

sudo chmod 644 /etc/ssl/certs/mail.example.com.crt
sudo chmod 600 /etc/ssl/private/mail.example.com.key
sudo chown root:root /etc/ssl/private/mail.example.com.key

Step 3: Configure submission port

# /etc/postfix/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_tls_cert_file=/etc/ssl/certs/mail.example.com.crt
  -o smtpd_tls_key_file=/etc/ssl/private/mail.example.com.key

Step 4: Verify certificate

sudo openssl x509 -in /etc/ssl/certs/mail.example.com.crt -text -noout | grep -E "Subject:|Not Before|Not After"

Step 5: Test TLS connection

openssl s_client -connect mail.example.com:587 -starttls smtp

Step 6: Check TLS logs

sudo tail -f /var/log/mail.log | grep -i tls

Prevention Tips

  • Use Let's Encrypt certificates with auto-renewal
  • Set smtpd_tls_security_level = encrypt on submission port
  • Enable smtp_tls_loglevel = 1 for TLS troubleshooting
  • Monitor certificate expiry dates

Common Mistakes with tls config

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world POSTFIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does Postfix say "TLS handshake failed"?

The certificate and key files might not match, or the key has incorrect permissions. Run openssl x509 -noout -modulus -in cert.pem | md5sum and compare with openssl rsa -noout -modulus -in key.pem | md5sum. They must match.

What is the difference between smtpd_tls_security_level = may and encrypt?

may offers TLS but does not require it (clients can connect without TLS). encrypt requires TLS for all connections on that port. Use may on port 25 and encrypt on port 587 (submission).

How do I set up Postfix to use Let's Encrypt certificates?

Symlink the Let's Encrypt certificates: sudo ln -s /etc/letsencrypt/live/mail.example.com/fullchain.pem /etc/ssl/certs/ and sudo ln -s /etc/letsencrypt/live/mail.example.com/privkey.pem /etc/ssl/private/. Set up a post-renewal hook to reload Postfix.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro