> For the complete documentation index, see [llms.txt](https://software-help-docs.gitbook.io/knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://software-help-docs.gitbook.io/knowledge-base/software-guide/mailgun/setting-up-mailgun-in-cloudflare.md).

# Setting up Mailgun in Cloudflare

This article will walk you through the full process of setting up your Mailgun account in Cloudflare.

For information on how to setup a Mailgun account, see article "Mailgun Setup".

If you are transferring your domain into Cloudflare from another DNS provider, please do so before continuing with this article.

### **Step 1: Retrieve MX and TXT records from Mailgun**

Log into your account in Mailgun and add a domain from the top menu bar. Once your domain is added, you will see that Mailgun gives you a few MX records and TXT records to be added for your domain, for both successful email forwarding and verification of the domain.

### **Step 2: Add MX and TXT records into CloudFlare**

### **Choose your site and select DNS Settings**

* Add the CNAME record. Name = email, Value = mailgun.org, TTL = Automatic **(these are examples, please use the actual items from your account)**
  * **IMPORTANT:** Make sure the Cloudflare cloud is gray and not orange/active => You have to click on the cloud icon to change this to DNS only
* Add the two MX records **(these are examples, please use the actual items from your account)**
  * Name = domain.com (no www), value = mxa.mailgun.org, Priority = 10
  * Name = domain.com (no www), value = mxb.mailgun.org Priority = 10
* Add the two TXT records **(these are examples, please use the actual items from your account)**
  * Name= domain.com (no www), value = v=spf1…
  * Name = smtp.\_domainkey, value = k=rsa…

### **Step 3: Add your mail routes in Mailgun**

1. Log into your Mailgun account and go to Routes section from the top menu. Now add as many routes as you want.
   * For example, if your domain is example.com and you want the mail sent to <hello@example.com> to be forwarded to <doctor@who.com>, then that would be a route.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://software-help-docs.gitbook.io/knowledge-base/software-guide/mailgun/setting-up-mailgun-in-cloudflare.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
