554 5.4.0 is a permanent routing error. The standard meaning is vague, but in practice it is most often Postfix’s “too many hops” reply: the message passed through so many servers that Postfix decided it must be stuck in a loop. Find the loop in the headers and break it.
The error message
From the Postfix source, the reply for a message over the hop limit is:
554 5.4.0 Error: too many hops
Postfix’s hopcount_limit setting is documented as “The maximal number of Received: message headers that is allowed in the primary message headers. A message that exceeds the limit is bounced, in order to stop a mailer loop.” The default is 50.
What it means
In RFC 3463, X.4.0 is “Other or undefined network or routing status”: something went wrong with networking or routing that no more specific code describes. 554 in RFC 5321 is “Transaction failed”.
Every mail server that handles a message adds a Received: header. RFC 5321 notes that counting those headers is an effective way to detect loops, and recommends a large threshold, normally at least 100. Postfix uses 50. When the count passes the limit, the server stops the loop by bouncing the message instead of passing it on again.
Why it happens
- Forwarding rules that point at each other, for example mailbox A forwards to B and B forwards to A.
- An MX record pointing to the wrong server, which hands mail back to the server that sent it.
- A relay host set to itself, or a server that is both told to accept and to relay the same domain.
- Two systems both claiming a domain, such as an old on-premises server and a new cloud provider during a migration.
- Auto-replies or ticket systems answering each other.
- Other 5.4.0 cases: some servers use 5.4.0 for DNS or routing failures with their own text.
How to fix it
- Get the full headers of the bounced message (attached to the bounce, or in Show original).
- Read the
Received:lines from the bottom up. You will see the same servers repeat. Note where the repeating pattern starts. - Check forwarding. Look for mailbox forwarding, aliases and server rules that send to an address which sends back.
- Check the MX record for the recipient domain:
Make sure it points to the server that should finally store the mail, not a relay that forwards back.dig MX example.com +short - Check relay settings on your own server, such as Postfix
relayhostand transport maps, so a domain is either delivered locally or relayed, not both. - During migrations, make sure only one system treats the domain as its own, and the other forwards to it.
- Stop auto-reply loops by having automated mail send
Auto-Submitted: auto-generated(RFC 3834) and by not replying to messages that carry it. - Raise
hopcount_limitonly if a legitimate path really needs more than 50 hops, which is rare.
Which server sent it
| Provider | Loop reply |
|---|---|
| Postfix servers | 554 5.4.0 Error: too many hops |
| Gmail | 554 5.4.6 Message exceeded 50 hops, this may show a mail loop. |
| Microsoft | Routing loop: 5.4.6 (on-premises Exchange) or 5.4.14 (Exchange Online). Exchange breaks a loop after 20 iterations. |
| Yahoo | Not listed by number. |
| Other servers | X.4.0 for other routing problems, with their own text. |
Is it temporary?
No. 554 is permanent, and the message will not be retried. Resending without fixing the loop produces the same bounce, and may put more load on the servers involved. Fix the routing, then send again.
How Mailcandor handles it
Loops usually live in inbound and forwarding setups. If you receive mail with Mailcandor’s inbound email, you point a domain’s MX at inbound-smtp.us-east-1.amazonaws.com and each message fires an email.received webhook to your app instead of passing through a chain of forwarding rules. For outbound mail, the deliverability coach explains bounces in plain English, and hard bounces are suppressed automatically. Look up any code with the free bounce code lookup, see SPF, DKIM and DMARC setup, or browse all error codes. More free checks are on the tools page.