Postfix refuses to send with "Relay access denied"
554 5.7.1 <user@example.net>: Relay access deniedShort answer
Postfix says Relay access denied when a client asks it to deliver to a domain it does not host, and the client is neither listed in mynetworks nor logged in with SASL. The mail log names the client IP and the service that took the connection; from there you either trust that IP, make the client authenticate on port 587, or fix the restriction order.
Fix it fast
1Find out which cause you have
Find the refused attempt in the mail log. The address in brackets is the client Postfix saw, and the process name (postfix/smtpd or postfix/submission/smtpd) tells you which port it came in on. Then check whether that client tried to log in at all.
sudo grep "Relay access denied" /var/log/mail.log | tail -n 5 sudo grep "198.51.100.20" /var/log/mail.log | grep -iE "sasl|auth" | tail -n 52Match what you see, then jump to its fix
- 1
Refusals for the IP of your own app server, container or device, which has no username to log in withThe sending server is not in mynetworksFix - 2
No SASL lines for the client's IP, and the app's mail settings have no username or have authentication switched offThe client never logs inFix - 3
The refusal is logged by postfix/smtpd (port 25), not postfix/submission/smtpd, although the app has a username and passwordThe client sends to port 25, where logins are offFix - 4
swaks shows 235 2.7.0 Authentication successful, and the recipient is still refusedThe restriction list rejects before it permitsFix - 5
Outside senders get Relay access denied when they write to an address at one of your own domainsMail for your own domain is refused because Postfix does not know it hosts itFix
- 1
What does the error look like?
554 5.7.1 <user@example.net>: Relay access denied454 4.7.1 <user@example.net>: Relay access deniedNOQUEUE: reject: RCPT from unknown[198.51.100.20]: 554 5.7.1 <user@example.net>: Relay access denied; from=<app@example.com> to=<user@example.net> proto=ESMTP helo=<web01>smtplib.SMTPRecipientsRefused: {'user@example.net': (554, b'5.7.1 <user@example.net>: Relay access denied')}
Cause 1 of 5
The sending server is not in mynetworks
1Check
Since Postfix 3.0 the default mynetworks_style is host, so only the mail server itself is trusted. An app on another machine, a Docker container or an office printer counts as a stranger. See what Postfix trusts right now.
postconf mynetworks mynetworks_style2Fix
Add that exact address, or a small private subnet, never a public range. If the app can log in, give it a login instead of trusting its IP.
sudo postconf -e 'mynetworks = 127.0.0.0/8 [::1]/128 10.0.0.12/32'
sudo systemctl reload postfix3Verify
The next message from that server gets a queue id and status=sent instead of NOQUEUE.
sudo grep "10.0.0.12" /var/log/mail.log | tail -n 3Cause 2 of 5
The client never logs in
1Check
With smtpd_tls_auth_only = yes, Postfix offers AUTH only after STARTTLS, so a client that skips TLS never sees it and sends as a stranger. Ask the server what it offers once TLS is up.
openssl s_client -connect mail.example.com:587 -starttls smtp -quiet
# then type: EHLO test and look for a 250-AUTH line2Fix
Set the client to port 587 with STARTTLS and a mailbox user and password. On the server, make sure Postfix can reach its authentication backend; with Dovecot that is a socket inside the Postfix queue directory.
# /etc/postfix/main.cf
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
# /etc/dovecot/conf.d/10-master.conf
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
sudo systemctl restart dovecot && sudo systemctl reload postfix3Verify
Send a test the way the client should, with a real login. swaks asks for the password when you leave it out.
swaks --server mail.example.com --port 587 --tls --auth LOGIN --auth-user app@example.com --from app@example.com --to you@example.netCause 3 of 5
The client sends to port 25, where logins are off
1Check
Port 25 is where other servers deliver mail to you, and SASL is normally enabled only on the submission ports 587 and 465. A client with the right password on port 25 never gets to use it. Check which services exist and whether AUTH is on globally.
postconf -M submission/inet submissions/inet
postconf smtpd_sasl_auth_enable2Fix
Enable the submission service in master.cf with its own overrides, reload, and point the client at 587 with STARTTLS (or 465 with implicit TLS if you also enable submissions).
# /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_auth_only=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
sudo postfix check && sudo systemctl reload postfix3Verify
Port 587 is listening, and the next attempt is logged under postfix/submission.
sudo ss -ltnp | grep ':587'Cause 4 of 5
The restriction list rejects before it permits
1Check
Postfix reads each restriction list from left to right and stops at the first match. If reject_unauth_destination sits before permit_sasl_authenticated, or a -o override in master.cf replaces the list without permit_sasl_authenticated, logged-in users are refused. Old guides also put relay rules in smtpd_recipient_restrictions, which is still checked after smtpd_relay_restrictions.
postconf -n | grep -E 'relay_restrictions|recipient_restrictions'
postconf -P | grep -E 'relay_restrictions|recipient_restrictions'2Fix
Put the permits first and the reject last, in main.cf and in every override. reject_unauth_destination answers with the permanent 554; Ubuntu's default ends in defer_unauth_destination, which answers 454 so a mistake is retried instead of bounced.
sudo postconf -e 'smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
sudo systemctl reload postfix3Verify
postconf prints the new order, and the authenticated test from swaks now ends with 250 2.0.0 Ok: queued.
postconf smtpd_relay_restrictionsCause 5 of 5
Mail for your own domain is refused because Postfix does not know it hosts it
1Check
A domain that is not in mydestination, virtual_mailbox_domains, virtual_alias_domains or relay_domains is treated as somebody else's, so mail for it from strangers counts as relaying. This tends to show up after adding a second domain or moving mailboxes to a virtual setup.
postconf mydestination virtual_mailbox_domains virtual_alias_domains relay_domains2Fix
List the domain in exactly one of those classes: mydestination for local system users, virtual_mailbox_domains for mailboxes kept in a file or database, relay_domains when this host only passes mail on to another server.
# if the setting points at a table (hash:, mysql:), add the domain to that table instead
sudo postconf -e 'virtual_mailbox_domains = example.com, example.org'
sudo systemctl reload postfix3Verify
An unauthenticated test from outside to the new domain is now accepted on port 25.
swaks --server mail.example.com --port 25 --from test@example.net --to info@example.orgHow do I stop it coming back?
- Give each app its own SASL login on port 587 rather than widening mynetworks.
- After every change run postfix check and keep the output of postconf -n under version control.
- Test from outside that the server is not an open relay: an anonymous message to a domain you don't host must be refused.
- Keep port 25 for incoming mail only, and allow logins on 587 and 465.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Related fixes
Mail from your own domain keeps landing in the spam folder
dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=example.com
Open a message that went to spam and read its Authentication-Results header: it shows whether SPF, DKIM and DMARC passed, and for which domain.
5 causes, each with a fixDovecot refuses to start: Can't load SSL certificate, no valid PEM certificate
doveconf: Error: ssl enabled, but ssl_cert not set
Dovecot reads the ssl_cert setting as the file's contents, not a path, so in 2.3 the value must start with a less-than sign.
3 causes, each with a fixOutlook.com bounces your mail with 550 5.7.515
status=bounced (host hotmail-com.olc.protection.outlook.com[...] said: 550 5.7.515 Access denied
550 5.7.515 means Outlook.com counts your From domain as a high-volume sender (5,000 or more messages a day to Microsoft consumer addresses) and the message failed its authentication rules.
4 causes, each with a fixSpamAssassin adds SPF_HELO_NONE to mail sent from your Postfix server
X-Spam-Status lists SPF_HELO_NONE even though SPF for your From domain passes
The receiver checked SPF for the name your server gave in HELO and found no record.
2 causes, each with a fixPHP mail() returns true but the email never arrives
Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing
mail() returning true only means the message was accepted for delivery, not that it arrived.
4 causes, each with a fixCodeIgniter email does not send and shows no error message
$email->printDebugger() prints an empty result
CodeIgniter signals a failed email only by send() returning false, with no exception.
4 causes, each with a fix