Bouncewise

Bouncewise › Guides › Mailgun error codes: API responses and delivery failures

Mailgun guide

Mailgun error codes: API responses and delivery failures

By the Bouncewise team · Updated · 4 min read · How we check guides

Short answer

Mailgun errors come from two places. The HTTP API answers your request with a standard status (400 bad request, 401 for a wrong or missing API key or a blocked IP, 403 for a key without permission, 404 for a missing resource or wrong region, 420 or 429 when you hit a rate limit, 500 for Mailgun's own errors) and a JSON message. Problems after Mailgun has accepted a message show up as failed or rejected events in the logs, with the receiving server's SMTP code or Mailgun's own text, such as "Not delivering to previously bounced address" or "Too old".

HTTP API status codes

Error bodies are JSON with a message key: {"message": "…"}. Read it first; it usually names the field or the problem.

StatusMailgun's descriptionWhat to do
200Success. On a send: "message": "Queued. Thank you."Nothing; the message is accepted, not yet delivered (accepted vs delivered).
400Bad Request; the JSON message has the detailsFix the parameter or value the message names.
401Unauthorized: invalid or missing API keySee the next section.
403Forbidden: valid credentials, but no access to the resourceThe key's role (Admin, Developer, Support or Analyst) doesn't allow this call; use a key with a role that does.
404Not Found; may be temporary, as the system is eventually consistentCheck the domain name and region. A missing JSON body usually means a wrong endpoint path.
420Returned instead of 429 for the recipients rate limit of /messagesSlow down sending; contact Mailgun if you need a higher limit.
429Rate LimitedBack off using X-RateLimit-Reset, then retry.
500Internal ErrorRetry with exponential backoff; contact support if it persists.

Every API response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (Unix milliseconds until the window resets), so you can slow down before you hit 429.

401 Forbidden: why Mailgun rejects your key

Mailgun's help centre describes the HTTP API's authentication failure as 401 Forbidden, and the SMTP equivalent as 535 Authentication failed. In order of likelihood:

  1. Wrong credentials format. The API uses HTTP Basic auth with the literal user name api and your key as the password: --user "api:$MAILGUN_API_KEY". Sending the key as a Bearer token, or with another user name, fails.
  2. Wrong or deleted key. Keys can be rotated or expired by an admin; a key copied from an old config may be gone. SMTP credentials are not API keys.
  3. IP allowlist. If the account has an IP allowlist, only listed IPs may use the API or SMTP. Since April 2024 the allowlist covers SMTP too, so a new server or a changed cloud IP starts failing until you add it under Profile › IP Access Management.

A key that authenticates but lacks a role's permission gets 403 instead. A request to the wrong region usually gets 404 with Domain not found, not 401: see US vs EU region.

Delivery errors in failed and rejected events

After a 200, errors appear in the logs and webhooks. These are Mailgun's own messages, from its help centre:

What you seeMeaningWhat to do
Not delivering to previously bounced addressThe address is on the domain's Bounces list after an earlier hard bounce; Mailgun didn't try.Remove it only if the mailbox now exists (Mailgun suppressions).
Not delivering to unsubscribed addressOn the Unsubscribes list.Leave it unless the recipient opts in again.
Not delivering to a user who marked your messages as spamOn the Complaints list.Don't resend; remove only on the recipient's explicit request.
Too oldTemporary failures until the retry window (8 hours by default) ran out.The earlier temporary failures show the real cause (permanent vs temporary).
498 No MX for + domaindelivery-status.code 498: the recipient domain has no MX records, often a typo like yahoo.comm.Correct the address and send a new message; permanent failures aren't retried.
Sandbox subdomains are for test purposes only… (rejected)Sent from the sandbox to an address that isn't an activated authorized recipient.Add the recipient or your own domain.
Relaying Denied from Mailgun's SMTP serverThe SMTP session wasn't authenticated before RCPT TO.Configure SMTP authentication with the domain's SMTP credentials.

Anything else in delivery-status.message is the receiving server's own reply, with its SMTP code in code and enhanced-code. Mailgun's classified bounces list shows typical ones, such as Gmail's 421 4.7.28 rate limit for unusual rates of unsolicited mail from your DKIM domain. Look those up in SMTP bounce codes.

When Mailgun won't send from a domain at all

Some errors block a whole domain or account rather than one recipient. The reason text in the error or the control panel banner tells you which:

  • Sandbox restrictions. The sandbox domain only sends to up to 5 authorized recipients. On the Free plan without card details, Mailgun's help centre says custom domains are also restricted to authorized recipients.
  • Domain not verified. Mailgun uses DNS verification to confirm you are authorised to send from a domain; until its records pass, sending from it is limited. See Mailgun domain verification.
  • Poor mailing list. Too many messages bounced as invalid addresses, so Mailgun disabled the domain. Clean the list and open a support ticket explaining how you collect addresses.
  • Business verification is required. The account is disabled or rate limited until you complete the business verification form linked from the red banner in the control panel.

None of these is fixed by retrying in code; stop the queue in your app and resolve the account side first.

Questions

What does Mailgun error 401 Forbidden mean?

Mailgun didn't accept your credentials: the API key is wrong, deleted or sent in the wrong format, or the request came from an IP that isn't on the account's IP allowlist. Use Basic auth with the user name api and the key as the password.

Is Mailgun's 420 the same as 429?

Both mean a rate limit. Mailgun returns 420 only for the recipients rate limit on /messages and 429 for every other limit.

What is error 498 in Mailgun?

A permanent failure meaning the recipient's domain has no MX records, so there is nowhere to deliver. It is usually a misspelt domain; correct the address and send again.

What does "Too old" mean in Mailgun?

Mailgun kept getting temporary failures until the retry window ended (8 hours by default), then dropped the message as a permanent failure.

Sources