How to Fix Postfix TLS Configuration Error
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 = encrypton submission port - Enable
smtp_tls_loglevel = 1for TLS troubleshooting - Monitor certificate expiry dates
Common Mistakes with tls config
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - 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
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro