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.

TypeHostPurpose
TXTmail.yourdomain.comSPF — v=spf1 include:mailgun.org ~all
TXTmailo._domainkey.mail.yourdomain.comDKIM public key
CNAMEemail.mail.yourdomain.comTracking and bounce handling
MXmail.yourdomain.comReceiving 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 domain — mail.yourdomain.com (a domain, not an address)
  • Mailgun sending domain — the same domain as you added in Mailgun
  • Region — us 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.

Latest from the blog

What we have been writing about hosting, SEO and running sites at scale.

SEO and Link Building from the Hosting Layer: A 2026 Operator's View

How hosting shapes indexing and link equity in 2026: keeping pages indexed, vetting aged domains before you build on them, link building without a footprint, and an honest line on what infrastructure can and cannot do for SEO.

Read the post →

Making WordPress Fast and Secure: A Performance and Plugin Checklist

A practical checklist for fast, secure WordPress: server-level caching, a per-site object cache, the handful of plugins worth running, keeping the stack current, and the WooCommerce pages you must never cache.

Read the post →

How to Choose Managed Web Hosting in 2026: A Buyer's Guide

What actually separates good managed hosting from a cheap box with a control panel — migrations, backups, isolation, real caching and honest scaling — and how to judge it before you commit.

Read the post →

Read the blog →

Still stuck?

Support is included on every plan, the desk is open 24 hours a day, and you can write to us in any of our 58 languages — we answer you in yours.

Contact support → All articles →