Skip to content
Latchkey

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

  1. Confirm the exact domain name in the Mailgun dashboard.
  2. Set MAILGUN_DOMAIN to that value.
  3. 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

Run this faster and cheaper on Latchkey managed runners. Start free →