# Cloudflare Domain Setup

### Introduction

Setting up custom domains with Mailgun can be a bit challenging for some users. This guide aims to simplify the process, using a video tutorial as a reference. By the end, you'll have a clear understanding of how to set up Mailgun custom domains, particularly with Cloudflare, though the principles can be applied to any DNS provider.

### Overview

The process involves:

1. Logging into Mailgun and your DNS provider (Cloudflare in this example).
2. Creating a subdomain in Mailgun.
3. Adding the necessary DNS records in your DNS provider.
4. Verifying the DNS records in Mailgun.

## Step-by-step Mailgun Setup <a href="#step-by-step-mailgun-setup" id="step-by-step-mailgun-setup"></a>

1\. Sign up for [Mailgun.com](https://signup.mailgun.com/new/signup)

2\. Check your email inbox to verify the email address<br>

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284378416/original/VewuZVN3oFOFIvBdf4XqMAOX4vtVGv_jNg.png?1677630998" alt=""><figcaption></figcaption></figure>

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284378421/original/GU6IL6Y3N81qm6KMH9aTz7l5FV5IEv7ySA.png?1677630999" alt=""><figcaption></figcaption></figure>

3\. Login to Mailgun, Click on **Sending** > **Add New Domain**<br>

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284378418/original/kxsnymCeuFAsBWkXaOes6QaaWED2_bfASA.png?1677630999" alt=""><figcaption></figcaption></figure>

4\. If your domain is companyname.com, you can either set up the main domain or subdomain with Mailgun.&#x20;

A. Main domain:

* If you are adding the main domain,[ it should not be used with Gsuite, or any other email provider](https://help.mailgun.com/hc/en-us/articles/203357040-Can-I-Use-the-Same-Domain-Name-for-Mailgun-and-for-Google-Apps-Or-Another-Email-Server-)&#x20;

&#x20;   Subdomain:

* To set up the subdomain with Mailgun, you can type **ANYTHING\_HERE**.companyname.com
  * Examples:
    * mg.companyname.com
    * replies.companyname.com
    * support.companyname.com

B. Please set up the domain or subdomain under US, **not EU. not EU. not EU.**&#x20;

C. Click on **Add domain**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284382652/original/woVjMqNw3YY_Zjs20LoBHUb4KrThVvj_Rw.png?1677635102" alt=""><figcaption></figcaption></figure>

The next screen that you're taken to will ask you to add DNS records to your domain. Leave this screen open for the next step.

<figure><img src="https://help.mailgun.com/hc/article_attachments/8759612958491/Screen_Shot_2022-09-11_at_6.39.22_PM.png" alt=""><figcaption></figcaption></figure>

5\. Now log in to your DNS records based on where you get the domain and add the 5 DNS records.

### To add the 1st TXT record <a href="#to-add-the-1st-txt-record" id="to-add-the-1st-txt-record"></a>

\
To [Add your first TXT record](https://developers.cloudflare.com/dns/manage-dns-records/how-to/create-dns-records/), Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login) and select an account and domain.

Click on **DNS > Records**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284386950/original/7Br2BkIKLhDBiHeqj6uRhzUTM68HZihKIQ.png?1677639074" alt=""><figcaption></figcaption></figure>

Click on **+ Add Record**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387199/original/vr_JbieNqi07EUV9m4GhTYCExqDcTOc-zw.png?1677639281" alt=""><figcaption></figcaption></figure>

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387183/original/Y8NTiChTf60Ju-PPIBkxMoPvepF9sUSQqQ.png?1677639258" alt=""><figcaption></figcaption></figure>

A. Type: Select **TXT** from the Type menu options.

B. Name: **DO NOT INCLUDE THE ROOT DOMAIN**

* Depending on the subdomain you are trying to set up, if you are trying to set up
  * [mg.companyname.com](https://mg.companyname.com/) The host name will be **mg**
  * [replies.companyname.com](https://replies.companyname.com/) The host name will be **replies**
* If you are setting up a **main** domain like companyname.com, the host name will be **@**

C. Content: Same for everyone

* paste the following record **v=spf1 include:mailgun.org \~all**

D. Click on **Save**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284384681/original/QCbqi3BnzhNKNCspyADXNWBZfk3F55e2dg.png?1677636916" alt=""><figcaption></figcaption></figure>

### To add the 2nd TXT record <a href="#to-add-the-2nd-txt-record" id="to-add-the-2nd-txt-record"></a>

Click on **+ Add Record** again

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387388/original/pGwHEEJ73iotP2Px-sz8EMcZlT852MZg1g.png?1677639444" alt=""><figcaption></figcaption></figure>

<br>

A. Type: Select **TXT** from the Type menu options.

B. Name: it's a bit tricky but the key here is to copy everything from the beginning until the subdomain part, **DO NOT INCLUDE THE ROOT DOMAIN**

**\*\*Everyone's 2nd TXT record host name and value is different**

Examples: **copy the highlighted part ONLY**

| <p>Example 1 using subdomain:</p><p><br></p><p>Copy mx.\_domainkey.helpdesk as the host name</p> | [![](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284380215/original/t6MGY8Bw9AK1Vv01kUxtJAkNwp_4UfYjHw.png?1677632945)](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284380215/original/t6MGY8Bw9AK1Vv01kUxtJAkNwp_4UfYjHw.png?1677632945) |
| ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>Example 2 using main domain:</p><p><br></p><p>Copy mailo.\_domainkey as the host name</p>     | [![](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284380223/original/JSERXQQhYNvzVp7YoXhIji_yeomZNLXUKA.png?1677632951)](https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284380223/original/JSERXQQhYNvzVp7YoXhIji_yeomZNLXUKA.png?1677632951) |

C. Content: Head back to Mailgun and Copy the 2nd TXT record here **highlighted in the screenshot below**

* Content: paste the 2nd very long copied TXT record here

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284385043/original/UvAhE3LGN5sYkTb4kyEsXNM0GE0Uc8Eq1Q.png?1677637220" alt=""><figcaption></figcaption></figure>

D. Click on **Save**

### To add the 1st MX records <a href="#to-add-the-1st-mx-records" id="to-add-the-1st-mx-records"></a>

Click on **+ Add Record** again

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387485/original/P9K8ytrObBrwMJdpaEBYJYuK3S7Z-iq5yg.png?1677639588" alt=""><figcaption></figcaption></figure>

If you have a Gsuite account to capture incoming emails for the main domain. Make sure you are using a subdomain for Mailgun. Check out [Can I Use the Same Domain Name for Mailgun and for Google Apps (Or Another Email Server)?](https://help.mailgun.com/hc/en-us/articles/203357040-Can-I-Use-the-Same-Domain-Name-for-Mailgun-and-for-Google-Apps-Or-Another-Email-Server-)

A. Type: Select **MX** from the Type menu options.

B. Name: Different for everyone

Depending on the subdomain you are trying to set up, if you are trying to set up

[mg.companyname.com](https://mg.companyname.com/) The host name will be **mg**

[replies.companyname.com](https://replies.companyname.com/) The host name will be **replies**

If you are setting up a **main** domain like companyname.com, the host name will be **@**

C. Mail Server: Same for everyone

&#x20;   paste the following data **mxa.mailgun.org**&#x20;

D. Priority is **10** which is also same for everyone no matter what domain you are trying to set

E. Click on **Save**

### To add the 2nd MX records <a href="#to-add-the-2nd-mx-records" id="to-add-the-2nd-mx-records"></a>

Click on **+ Add Record** again

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387662/original/7FOCRV3g2jhAT9ogHOZI9nNtWZiNGsDqlQ.png?1677639703" alt=""><figcaption></figcaption></figure>

A. Type: Select **MX** from the Type menu options.

B. Name: Different for everyone

Depending on the subdomain you are trying to set up, if you are trying to set up

[mg.companyname.com](https://mg.companyname.com/) The host name will be **mg**

[replies.companyname.com](https://replies.companyname.com/) The host name will be **replies**

If you are setting up a **main** domain like companyname.com, the host name will be **@**

C. Mail Server: Same for everyone

&#x20;   paste the following data **mxb.mailgun.org**&#x20;

D. Priority is **10** which is also same for everyone no matter what domain you are trying to set

E. Click on **Save**

### To add the CNAME record <a href="#to-add-the-cname-record" id="to-add-the-cname-record"></a>

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284385721/original/3LyKoigujZ-vEjMFQDflCfmRRfAJra3rYA.png?1677637907" alt=""><figcaption></figcaption></figure>

In Cloudflare, Click on **+ Add Record** again

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387826/original/6ADDI371NG-0XbruZ2zs5EF4QgaagbkXqQ.png?1677639817" alt=""><figcaption></figcaption></figure>

A. Type: Select **CNAME** from the Type menu options.

B. Name: Different for everyone

Head back to Mailgun to copy the host name, it's a bit tricky but the key here is to copy everything from the beginning until the subdomain part, **DO NOT copy the main domain**

Depending on the subdomain you are trying to set up, if you are trying to set up

* mg.companyname.com The host name will be **email.mg**
* replies.companyname.com The host name will be **email.replies**

If you are setting up a **main** domain like companyname.com, the host name will be **email**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284385985/original/OtLw_A4zY8FbLbBKqMB9kUKRaQJO3xpp8A.png?1677638165" alt=""><figcaption></figcaption></figure>

C. Target: Same for everyone

&#x20;       paste the following data **mailgun.org**

D. Click on the orange cloud Proxied to make it **DNS only**

E. Click on **Save**

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387917/original/KyyhGEhxb0QZRZCV2f8MAaNP6jb9n37nvA.png?1677639894" alt=""><figcaption></figcaption></figure>

Now that you have added 5 records, Go back to Mailgun and click on **Verify DNS Settings**

Click the same button to **Verify DNS Settings** again if some records are still not showing the green checkmark

<figure><img src="https://s3.amazonaws.com/cdn.freshdesk.com/data/helpdesk/attachments/production/48284387965/original/I7T5QQCSjAnBvT1zqQlVgXSuNdgfuNiM3w.png?1677639928" alt=""><figcaption></figcaption></figure>

### Conclusion

Setting up custom domains with Mailgun is a straightforward process once you understand the steps. This guide, combined with the video tutorial, should provide you with all the information you need to successfully set up your custom domain. Remember, while this example used NameCheap, the principles remain the same for other DNS providers.<br>
