How to Fix Postfix SMTP Relay Configuration Error
In this tutorial, you'll learn about How to Fix Postfix SMTP Relay Configuration Error. We cover key concepts, practical examples, and best practices.
Postfix returns Relay access denied or SASL authentication failed when trying to send mail through an external SMTP relay — the relay host configuration or authentication credentials are incorrect.
The Problem
Jun 24 10:00:00 mail postfix/smtp[1234]: 9A1B2C3D4E5F:
to=<user@example.com>, relay=smtp.example.com[10.0.0.1]:587,
delay=2.5, delays=0.1/0/2.4/0, dsn=5.0.0,
status=bounced (host smtp.example.com[10.0.0.1] said:
530 5.7.0 Authentication required)
Step-by-Step Fix
Step 1: Configure relayhost
# /etc/postfix/main.cf
relayhost = [smtp.example.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
Step 2: Set up credentials
# /etc/postfix/sasl_passwd
[smtp.example.com]:587 user@example.com:YOUR_PASSWORD
# Hash the file
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
Step 3: Test relay connectivity
echo "Test email body" | mail -s "Test Subject" recipient@example.com
Step 4: Check logs
sudo tail -f /var/log/mail.log
Step 5: Use null client (send only)
# /etc/postfix/main.cf
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = loopback-only
mydestination =
relayhost = [smtp.example.com]:587
Prevention Tips
- Use app-specific passwords for SMTP authentication
- Enable TLS for encrypted relay connections
- Store SASL passwords with restricted permissions (600)
- Monitor mail logs for relay failures and delays
Common Mistakes with smtp relay
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
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