Mailgun Setup - CloudFlare Domain Setup

Modified on: Wed, 1 Jul, 2026 at 7:18 AM

Email Infrastructure
Mailgun + Cloudflare Domain Setup
Step-by-step DNS configuration for connecting Mailgun to a domain managed through Cloudflare.
What You'll Learn

This guide walks through signing up for Mailgun, adding your domain, and configuring the five DNS records Mailgun requires — two TXT records, two MX records, and one CNAME — inside Cloudflare's DNS Records panel.

It also covers a Cloudflare-specific step that trips people up: switching the CNAME record from Proxied to DNS only.

Video Recap
1

Sign up for Mailgun & add your domain

Step 1

Sign up at Mailgun.com, then check your inbox to verify your email address.

Mailgun signup confirmation screen
Mailgun email verification confirmation
Step 2

Log in to Mailgun, then click Sending → Add New Domain.

Sending menu with Add New Domain option in Mailgun
Step 3

If your domain is companyname.com, decide whether to set up the main domain or a subdomain with Mailgun.

  • Main domain: if you use the main domain, it should not also be used with Google Workspace or any other email provider — see Mailgun's guidance on sharing a domain with another email server.
  • Subdomain: type ANYTHING_HERE.companyname.com — for example mg.companyname.com, replies.companyname.com, or support.companyname.com.
Important

Set up the domain or subdomain under the US region — not EU.

Click Add domain.

Adding a domain in Mailgun
Tip

The next screen asks you to add DNS records to your domain. Leave this screen open — you'll need it for the next step.

Mailgun DNS records screen to keep open for the next step
2

Access DNS records in Cloudflare

Now log in to your DNS records and add the 5 DNS records Mailgun requires.

Step 1

Log in to the Cloudflare dashboard and select your account and domain. See Cloudflare's own guide on creating DNS records if you'd like more detail.

Step 2

Click on DNS → Records.

DNS Records section in Cloudflare
Step 3

Click + Add Record. You'll repeat this for each of the 5 records below.

Add Record button in Cloudflare DNS
3

Add the 1st TXT record (SPF)

Add record form in Cloudflare
Fields

A. Type: select TXT from the Type menu.

B. Name: different for everyone — do not include the root domain.

  • mg.companyname.com → host name is mg
  • replies.companyname.com → host name is replies
  • Main domain (companyname.com) → host name is @

C. Content: the same for everyone — paste v=spf1 include:mailgun.org ~all.

D. Click Save.

Completed first TXT record in Cloudflare
4

Add the 2nd TXT record (DKIM)

Click + Add Record again.

Adding the second TXT record in Cloudflare
Fields

A. Type: select TXT from the Type menu.

B. Name: this part is a little tricky. Copy everything from the beginning of the value up until the subdomain part — do not include the root domain. Everyone's 2nd TXT record name and value are different.

ExampleName to copyHighlighted part
Using a subdomainmx._domainkey.helpdeskExample of the name value to copy when using a subdomain
Using the main domainmailo._domainkeyExample of the name value to copy when using the main domain

C. Content: head back to Mailgun and copy the 2nd, much longer TXT record — highlighted in the screenshot below — and paste it here.

Mailgun screen highlighting the long DKIM TXT record to copy

D. Click Save.

5

Add the 1st MX record

MX records overview in Cloudflare

Click + Add Record again.

Add MX record form in Cloudflare
Heads Up

If you have a Google Workspace account capturing incoming email for your main domain, make sure you're using a subdomain for Mailgun instead. See Can I Use the Same Domain Name for Mailgun and for Google Apps (Or Another Email Server)?

Fields

A. Type: select MX from the Type menu.

B. Name: different for everyone —

  • mg.companyname.com → host name is mg
  • replies.companyname.com → host name is replies
  • Main domain → host name is @

C. Mail Server: the same for everyone — paste mxa.mailgun.org.

D. Priority: 10 — the same for everyone, no matter what domain you're setting up.

E. Click Save.

6

Add the 2nd MX record

Click + Add Record again.

Add second MX record form in Cloudflare
Fields

A. Type: select MX from the Type menu.

B. Name: different for everyone —

  • mg.companyname.com → host name is mg
  • replies.companyname.com → host name is replies
  • Main domain → host name is @

C. Mail Server: the same for everyone — paste mxb.mailgun.org.

D. Priority: 10 — the same for everyone.

E. Click Save.

7

Add the CNAME record

CNAME records overview in Cloudflare

In Cloudflare, click + Add Record again.

Add CNAME record form in Cloudflare
Fields

A. Type: select CNAME from the Type menu.

B. Name: different for everyone. Head back to Mailgun to copy the host name — copy everything from the beginning up until the subdomain part, do not copy the main domain.

Mailgun CNAME host name to copy
  • mg.companyname.com → host name is email.mg
  • replies.companyname.com → host name is email.replies
  • Main domain (companyname.com) → host name is email

C. Target: the same for everyone — paste mailgun.org.

Important — Cloudflare-Specific

D. Click the orange cloud icon to switch it from Proxied to DNS only. If this record stays proxied, Mailgun won't be able to verify it and mail delivery will fail.

E. Click Save.

Completed CNAME record set to DNS only in Cloudflare
8

Verify DNS & finish setup

Now that you've added all 5 records, go back to Mailgun and click Verify DNS Settings. If some records still aren't showing a green checkmark, click the same button again — DNS propagation can take a little time.

Verify DNS Settings button in Mailgun
Next Steps

Once all records are verified, grab your Mailgun API key and add it to your email service settings.

Then send a test email to confirm everything works — see how to send a test email in the Conversation.

9

Frequently Asked Questions

Q: Why does the CNAME record need to be "DNS only" instead of "Proxied"?
Cloudflare's proxy sits in front of the record and changes how it resolves, which breaks Mailgun's ability to verify it. Setting it to DNS only (gray cloud) lets Mailgun see the record directly.
Q: Where do I find the +Add Record button in Cloudflare?
After selecting your domain, go to DNS → Records. The +Add Record button sits at the top of the records table.
Q: Do the TXT and MX records also need to be set to DNS only?
TXT and MX records aren't proxyable in Cloudflare — only records that resolve to a web-facing address (like CNAME and A records) show the proxy toggle. Only the CNAME record needs the DNS-only setting checked.
Q: Will this affect my existing Google Workspace or Gmail email?
Not if you use a subdomain for Mailgun rather than your main domain, and leave your existing MX records for Google Workspace untouched on the main domain.
Q: How long does DNS propagation take with Cloudflare?
Cloudflare's own DNS updates are typically fast, but it can occasionally take a few hours for changes to fully propagate. If a record isn't showing green yet in Mailgun, wait a bit and click Verify DNS Settings again.
Q: What do I do after all 5 records show a green checkmark?
Grab your Mailgun API key, add it to your email service settings, and send a test email in a conversation to confirm delivery is working.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article