Mailgun "Domain not found" error in CI
Mailgun returns {"message":"Domain not found: ..."} when the domain segment in the /v3/<domain>/messages URL is not a domain on your account, or is registered in the other region. The credentials may be fine; the domain path is wrong.
What this error means
A Mailgun send returns HTTP 404 with Domain not found: <domain>. It commonly appears after a typo in MAILGUN_DOMAIN or when a US host is used for an EU domain.
Mailgun API
< HTTP/1.1 404 NOT FOUND
{"message": "Domain not found: mg.example.com"}Common causes
The domain is misspelled or not verified
The MAILGUN_DOMAIN value does not match a verified domain on the account, so the path resolves to nothing.
Region mismatch
An EU-region domain queried against api.mailgun.net (US) is reported as not found.
How to fix it
Use a verified domain and matching host
- Confirm the exact domain name in the Mailgun dashboard.
- Set
MAILGUN_DOMAINto that value. - Use the US or EU API host that matches the domain region.
Terminal
MAILGUN_DOMAIN=mg.example.com
curl -sS --user "api:$MAILGUN_API_KEY" \
"https://api.mailgun.net/v3/$MAILGUN_DOMAIN/messages" -F ...Store the domain as a variable
Pin the domain as a workflow variable to prevent typos across steps.
.github/workflows/ci.yml
env:
MAILGUN_DOMAIN: ${{ vars.MAILGUN_DOMAIN }}How to prevent it
- Reference only verified domains from CI.
- Match the API host to the domain region.
- Keep the domain in a variable to avoid typos.
Related guides
Mailgun 401 Forbidden (bad API key) in CIFix Mailgun HTTP 401 Forbidden in CI - the API key is missing or wrong, or the basic-auth user is not "api".…
Mailgun sandbox domain "recipient not authorized" in CIFix Mailgun "not authorized to send to this recipient" from a sandbox domain in CI - sandbox domains only sen…
SendGrid 400 Bad Request (malformed mail/send) in CIFix SendGrid HTTP 400 Bad Request in CI - the mail/send JSON is missing a required field such as content, sub…