Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

Postfix 554 5.7.1 Relay access denied: who may send through the server

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

554 5.7.1 <user@example.net>: Relay access denied means a client asked this Postfix server to deliver mail to a domain it is not responsible for, and the client is neither on a trusted network nor logged in. Postfix refuses on purpose: accepting that mail would make the server an open relay.

Decide which of three legitimate routes the sender should use, then configure only that one: send from a trusted address, authenticate with SASL, or, if the recipient's domain really is yours, tell Postfix it is a domain it accepts. Do not widen trust to make the message go.

What the error means

Postfix decides about relaying while it handles each RCPT TO command. The smtpd_relay_restrictions parameter holds that policy. Its default, according to the postconf(5) manual, is permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination. By default, the manual explains, the Postfix SMTP server accepts:

  • mail from clients whose IP address matches $mynetworks;
  • mail from clients who are SASL authenticated;
  • mail to remote destinations that match $relay_domains, except for addresses with sender-specified routing;
  • mail to local destinations that match $inet_interfaces, $proxy_interfaces, $mydestination, $virtual_alias_domains or $virtual_mailbox_domains.

Anything else is refused. The Postfix documentation puts the principle this way: "By default, Postfix has a moderately restrictive approach to mail relaying. Postfix forwards mail only from clients in trusted networks, from clients that have authenticated with SASL, or to domains that are configured as authorized relay destinations."

Which restriction fired: 554 or 454

The reply code tells you which rule produced the refusal. In the Postfix 3.11.0 source, reject_unauth_destination replies with code relay_domains_reject_code (default 554) and enhanced status 5.7.1, and defer_unauth_destination replies with that code minus 100 (454) and enhanced status 4.7.1. Both produce the text <recipient>: Relay access denied. The manual says defer_unauth_destination will "reject the same requests as reject_unauth_destination, with a non-permanent error code."

So:

  • 554 5.7.1 came from reject_unauth_destination. It is not part of the default smtpd_relay_restrictions, so it comes from a setting in smtpd_relay_restrictions or smtpd_recipient_restrictions. A 5xx reply is a permanent failure.
  • 454 4.7.1 came from the default defer_unauth_destination. The manual calls this "a non-permanent error code", so the sender is expected to try again later. The NOQUEUE word in your mail log has a documented meaning: rejected recipients "are logged with NOQUEUE instead of a mail transaction ID (also known as a queue ID)", so a refusal has no queue ID to follow.

Likely causes

Cause What you see How to confirm
An application on another host sends without logging in, and its address is not in mynetworks Works from the mail server itself, refused from the application server The log line shows the application server's IP as the client; postconf mynetworks does not list it
The application's address changed after a move or a NAT change Worked before, fails after; the client address in the log is new Compare the logged client address with mynetworks
SASL is not enabled, or the client does not authenticate The client connects and sends RCPT TO with no AUTH step postconf smtpd_sasl_auth_enable shows no, or the client's settings have no username
SASL login happens only after TLS, and the client does not start TLS AUTH is not offered on a plain connection postconf smtpd_tls_auth_only shows yes and the client does not use STARTTLS
The recipient domain is yours but Postfix does not know it Mail from outside to a new hosted domain gets Relay access denied The domain is missing from mydestination, virtual_alias_domains, virtual_mailbox_domains and relay_domains
Restriction order or a missing permit A trusted client is refused permit_mynetworks or permit_sasl_authenticated is absent from smtpd_relay_restrictions, or an earlier rule rejects first

Prove the cause before changing anything

All of these read only.

1. Find the refusal in the mail log and note the client address, the sender and the recipient. Use the mail log your system writes. The Postfix manual's examples use /var/log/maillog; where your system writes the log depends on its logging setup and on the maillog_file parameter. Search for Relay access denied.

2. Print the settings that decide relaying. postconf -n prints "only configuration parameters that have explicit name=value settings in main.cf", and postconf followed by parameter names prints those parameters, including defaults.

postconf -n
postconf smtpd_relay_restrictions smtpd_recipient_restrictions mynetworks mynetworks_style mydestination relay_domains virtual_alias_domains virtual_mailbox_domains smtpd_sasl_auth_enable smtpd_tls_auth_only
postconf -d smtpd_relay_restrictions

postconf -d "print[s] main.cf default parameter settings instead of actual settings", so the last line shows what the default policy is on your version.

3. Check mynetworks against the client. The default mynetworks comes from mynetworks_style, which has default host on Postfix 3.0 and later ("Postfix should 'trust' only the local machine") and subnet before 3.0. The manual also gives a warning about class: "Caution: this may cause Postfix to 'trust' your entire provider's network." If the client's address is not listed, and the client does not authenticate, Postfix is behaving as designed.

4. For a domain that should be accepted, find its class. The reject_unauth_destination description lists the two cases: the domain matches $relay_domains (Postfix is a forwarder) or it is the final destination ($mydestination, $inet_interfaces, $proxy_interfaces, $virtual_alias_domains, $virtual_mailbox_domains). A domain in none of those is refused.

Example (illustrative): crm01 (203.0.113.25) sends invoices through mail01 (Postfix, 198.51.100.10). It used to be on the same subnet, but was moved. The log on mail01 shows a NOQUEUE line for the client at 203.0.113.25 with 554 5.7.1 <accounts@example.net>: Relay access denied. postconf mynetworks on mail01 lists 127.0.0.0/8 [::1]/128 198.51.100.0/24. The new address is outside every trusted range and crm01 sends without a login, so none of the three allowed routes applies.

Fix

Take a copy of main.cf first. For a config-only change, the copy is the way back.

Route 1: authenticated submission (the right default for applications)

Give the application its own mailbox or account and have it log in. First set up the SASL backend and test it, before you switch authentication on: until a backend works, no client can log in. Then Postfix's SASL documentation says that "enabling SMTP authentication in the Postfix SMTP server always requires setting the smtpd_sasl_auth_enable option":

smtpd_sasl_auth_enable = yes

and shows the relay policy that lets logged-in clients through, while still refusing strangers. Print the current value first with postconf smtpd_relay_restrictions, keep any rule of your own, and add only permit_sasl_authenticated before the final reject:

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination

You also need a SASL backend; smtpd_sasl_type defaults to cyrus, and the available types are listed by postconf -a. The SASL documentation walks through each implementation. One way to offer authenticated submission is a submission inet ... smtpd entry in master.cf; the master(5) manual shows that form with -o overrides. The parameter smtpd_tls_auth_only (default no) can require TLS before AUTH is offered. Read the result back with postconf smtpd_relay_restrictions and run postfix check before the reload.

Disruptive step: postfix reload "re-read[s] configuration files. Running processes terminate at their earliest convenience." Swapping the default defer_unauth_destination for reject_unauth_destination also turns a retryable 454 into a permanent 554 for strangers, so a sender whose mail is refused is told the failure is final. The SASL documentation's example uses the same rule. To back out, restore the saved main.cf and reload.

Route 2: trust one address

If authentication is not possible and the application sits on a controlled network, add the single address, not a range. Save a copy of main.cf first (cp /etc/postfix/main.cf /etc/postfix/main.cf.bak-20261119), then print the current value with postconf mynetworks, and add only the one address to it:

mynetworks = 127.0.0.0/8 [::1]/128 198.51.100.0/24 203.0.113.25/32

The manual's examples show the format, including [::1]/128 for IPv6 and a note that IPv6 addresses go inside square brackets. postconf -e "edit[s] the main.cf configuration file" with name=value pairs. Read the result back with postconf mynetworks and run postfix check; postfix(1) describes it as a warning about bad directory and file ownership or permissions, so it is not a full test of the new line.

Disruptive step: postfix reload ("Re-read configuration files") applies the new trust list, and from that moment every client at the added address may relay without a login. The postconf(5) notes say that changes become visible "after a minute or so" without the reload. Then run the negative test: send from a host that is not trusted and cannot log in, and confirm it still gets Relay access denied.

Risk: every client in mynetworks may relay to anywhere with no login. A shared NAT address, a flat network or an infected host behind that address inherits that right. The Postfix documentation warns what follows: "spammers abuse servers that forward mail from arbitrary systems, and abused systems end up on anti-spammer denylists." Prefer Route 1 whenever the application can authenticate. To back out, copy the saved main.cf back, run postfix check and reload.

Route 3: the domain is yours

If the recipient domain belongs to this server, add it to the right list rather than loosening relay control:

  • mydestination: domains delivered to local accounts;
  • virtual_alias_domains or virtual_mailbox_domains: hosted domains; the Postfix FAQ's entry for "Postfix refuses mail for virtual domains with 'relay access denied'" says to specify "a virtual alias domain as per the virtual(5) manual page" or "a virtual mailbox domain as per the virtual(8) manual page";
  • relay_domains: domains this server accepts mail for and then forwards onwards. The manual says Postfix validates recipients with relay_recipient_maps for these.

Keep each domain in one class; the FAQ entry above does not say this, but the mydestination manual warns: "Do not specify the names of virtual domains - those domains are specified elsewhere" and "Do not specify the names of domains that this machine is backup MX host for." The FAQ's backup-MX example repeats it for a relay domain: "DO NOT LIST the.backed-up.domain.tld in MYDESTINATION".

Risk: listing a domain in the wrong class, or in two, changes where all mail for it goes. Run postfix check before postfix reload. To back out, restore the saved main.cf and reload; mail already delivered to a wrong destination cannot be recalled.

Route 4: fix the policy order

A relay policy ends with a rule that refuses unknown destinations. The manual says "either the smtpd_relay_restrictions or the smtpd_recipient_restrictions parameter must specify at least one of the following restrictions. Otherwise Postfix will refuse to receive mail: reject, reject_unauth_destination, defer, defer_if_permit, defer_unauth_destination." Keep permit_mynetworks and permit_sasl_authenticated before it, as in the SASL example.

Risk: a permit placed before the final reject opens relaying to every client that rule matches, and a missing reject makes Postfix refuse to receive mail. Run postfix check before the reload. To back out, restore the saved main.cf and run postfix reload.

Confirm the fix

  1. Send a test message from the application, and from a host that is not trusted and cannot log in. The first must be accepted; the second must still get Relay access denied. The second test matters: it proves you have not created an open relay.
  2. Read the mail log for the accepted message: it now has a queue ID in place of NOQUEUE.
  3. Check that the message leaves the server, using the deferred-queue steps in "Postfix mail stuck in the queue as deferred: read the reason".
  4. For authenticated submission, confirm the client uses TLS and that its login works from outside the server's network.

What to watch afterwards

  • Recheck mynetworks whenever an address plan changes. A range that was once sensible becomes a hole after a move.
  • Alert if outbound volume or queue size rises suddenly; a queue of mail for unknown domains is a sign to check for an open relay.

Risks and limits

  • These commands have not been run or lab-tested. They are taken from the Postfix documentation and source listed below.
  • The reply codes and the text Relay access denied come from the Postfix 3.11.0 source. Other versions, and servers that are not Postfix, may use different codes and wording.
  • Postfix before 2.10 has no smtpd_relay_restrictions; relay rules there live in smtpd_recipient_restrictions, where a permissive spam policy could become a permissive relay policy.
  • SASL backend setup (Cyrus, Dovecot and their user databases) is a larger job than the Postfix lines above.
  • If a managed mail relay sits between the application and Postfix, the setting that needs changing may be theirs.

Sources