Skip to content

How to Fix Postfix SMTP Relay Configuration Error

DodaTech Updated 2026-06-24 2 min read

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

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' 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

### What does "Relay access denied" mean in Postfix?

The SMTP relay server rejected the connection because authentication is required or the credentials are invalid. Check the relay host's authentication requirements and ensure the username/password in sasl_passwd is correct and hashed with postmap.

How do I use different relays for different domains?

Use transport maps: create /etc/postfix/transport with example.com smtp.custom-relay.com:587, then postmap /etc/postfix/transport. In main.cf, add transport_maps = hash:/etc/postfix/transport.

Should I use port 25, 465, or 587 for SMTP relay?

Use port 587 with STARTTLS for mail submission. Port 465 is deprecated for submission (use SMTPS). Port 25 is for server-to-server relay and often blocked by ISPs. Port 587 is the standard for authenticated submission.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro