Knowledge base

Send email through your own Mailgun account

Connect your own Mailgun account: adding a sending subdomain, the SPF, DKIM and MX records to publish, a sending key rather than your private API key, and why an EU-hosted account returns 401 against the US host.

You will need a Mailgun account and access to your domain's DNS.

Mailgun's own documentation: Adding and verifying a domain · API keys · Sign up

1. Add your sending domain to Mailgun

In the Mailgun dashboard go to Send → Domains → Add New Domain and enter a subdomain, for example mail.yourdomain.com.

⚠️ Mailgun's own guidance is a subdomain, and it matters more here than with some providers: Mailgun sets its own SPF and DKIM records on whatever you give it, and pointing it at your root domain means those records sit alongside the ones your business mailboxes rely on.

Choose the region that matches where you want your data to live — US or EU. Write it down; you will need it in step 4, and it is the single commonest thing to get wrong.

2. Publish the DNS records Mailgun gives you

Mailgun shows you a list. Add every one of them at your DNS provider.

| Type | Host | Purpose | | --- | --- | --- | | TXT | mail.yourdomain.com | SPF — v=spf1 include:mailgun.org ~all | | TXT | mailo._domainkey.mail.yourdomain.com | DKIM public key | | CNAME | email.mail.yourdomain.com | Tracking and bounce handling | | MX | mail.yourdomain.com | Receiving bounces (Mailgun's two MX hosts) |

If your sending subdomain already has an SPF record, edit it — do not add a second. A domain with two SPF TXT records fails SPF outright, which is worse than having none at all.

Then press Verify DNS Settings in Mailgun. It can take up to an hour to go green.

Add the MX records even though you are only sending. They are how Mailgun collects bounces. Without them a bad address bounces to nowhere, Mailgun cannot suppress it, and you go on paying to send to an address that will never receive anything.

3. Get your API key

Send → Sending → Domain settings → API keys, or your account's API Keys page.

Use a sending key scoped to this domain if your plan offers one, rather than your account's private API key. A sending key can only send; the private key can read your logs and change your account. There is no reason for us to hold the second one.

4. Connect it in Zinn®

Open Email sending in your dashboard and fill in:

  • Provider — Mailgun
  • Send from this domainmail.yourdomain.com (a domain, not an address)
  • Mailgun sending domain — the same domain as you added in Mailgun
  • Regionus or eu, matching step 1
  • Mailgun API key — the key from step 3

⛔⛔ Get the region right. EU-hosted Mailgun accounts are served from a completely different API host. Sending an EU account's key to the US host returns "401 Unauthorized" — which reads exactly like a wrong key. If your key is definitely correct and you are getting 401, this is almost always why.

5. Send the test and enter the code

Press Send test message, using an inbox on a different domain — a Gmail address is ideal. Read the code out of that inbox and enter it. Your mail switches over immediately.

When it does not work

401 Unauthorized — wrong region (see above), or you pasted a key from a different Mailgun account. Regenerate the key rather than retyping it; the leading key- is easy to lose.

The test message never arrives — check Mailgun's Logs page. If Mailgun has no record of it at all, the credential or the domain name is wrong. If Mailgun accepted it and it failed afterwards, the reason will be there in plain words, and it is almost always DNS.

"Domain not found" — the Mailgun sending domain field must be exactly the domain as Mailgun lists it, including the subdomain. yourdomain.com and mail.yourdomain.com are two different domains to Mailgun.

It worked and then stopped — check whether your free trial ended. Mailgun trial accounts can only send to authorised recipients, so the test message to your own address keeps working while everything to your clients silently does not.

Still stuck?

Support is included on every plan and answers in your own language.

Contact support All articles
Send email through your own Mailgun account