# Configure Mailgun for email when using Digital Ocean for DNS

**URL:** https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590
**Category:** Sysadmins
**Tags:** email, how-to
**Created:** [March 4, 2016, 7:57pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590 "2016-03-04T19:57:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [March 4, 2016, 7:57pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/1 "2016-03-04T19:57:40Z")

</div>

I had a little bit of trouble to connect Mailgun and Digital Ocean (espacially the DNS configuration in Digital Ocean), so I’ve decided to create a little guide to help others :

## Connecting Mailgun with Digital Ocean

## Initial configuration in Mailgun

1. [**Sign up on Mailgun**](https://mailgun.com/signup)
2. Activate your account (you may have to wait 5-10 minutes to receive your activation mail)
3. In Mailgun, do to Domains, Add a New domain. In my example I didn’t use a subdomain as they recommended, I wanted my emails to be `noreply@mydomain.com` (_mine is [noreply@iunctis.fr](mailto:noreply@iunctis.fr), you’ll see this in this guide_)
4. In domains, you should have something like this in **Domain Verification & DNS** :  
 ![](https://global.discourse-cdn.com/meta/original/3X/8/5/850fd3b8683bcb981af29b8d02d3480e24f7a595.jpg)

## Configure DNS verification in Digital Ocean

1. In **Digital-Ocean** , go to **Networking** \> **Domains**  
(We have to setup the DNS Records, don’t follow the instructions in Mailgun)
2. Create a CNAME record, just put : `email` // `mailgun.org.`
3. Create a TXT record : `@` // `"v=spf1 include:mailgun.org ~all"` - The commas are recommended.
4. Create another TXT record : `mailo._domainkey` then the code given by Mailgun `"k=rsa; p=MIGfMA....."` - Again, the commas are recommended. Example:  
 ![](https://global.discourse-cdn.com/meta/original/3X/8/1/81b6ead7d25f6306ea919b8bd34c2e817f3bb240.jpg)

## Finalize configuration in Mailgun

1. Go to Mailgun again and click on `Check DNS Record Now`, after a few minutes, everything should be validated.
2. Now, you can change the email adresses you want to use (if you don’t want `postmaster@yourdomain` created by mailgun). In Mailgun \> Domains, you should have this on top of the page :  
 ![](https://global.discourse-cdn.com/meta/original/3X/1/1/11765c7020b09f833ce32ed1b019bb61b09e1614.jpg)  
In **Manage SMTP credentials** make sure to set an address and a long random password of alphanumerics - `a-z, A-Z, 0-9` - you’ll need it later.

## Update your Discourse

1. Launch Putty or any program you use to manage your server. Use these commands :

```plaintext
cd /var/discourse
nano containers/app.yml

```

2. In `app.yml`, you should have around the line 59, something like this :

```plaintext
## TODO: The mailserver this Discourse instance will use
DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org # (mandatory)
DISCOURSE_SMTP_PORT: 587 # (optional)
DISCOURSE_SMTP_USER_NAME: noreply@yourdomaine.com # (optional)
DISCOURSE_SMTP_PASSWORD: password # (optional)
DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)

```

You have to change `DISCOURSE_SMTP_USER_NAME` and `DISCOURSE_SMTP_PASSWORD`
3. Exit, save the file. If you want to be sure your app.yml haven’t been messed up, you can use the [YAML Validator](http://codebeautify.org/yaml-validator).
4. Rebuild the app using the command:

```plaintext
./launcher rebuild app`

```

This should go fine.

## Test the new mail server

Finally, in your Discourse, you can test the new mail server :

 ![](https://global.discourse-cdn.com/meta/original/3X/b/d/bd78787f2c4cf69e536c9ea2f32dbade0f92cef3.jpg) 

Send test email and you’re done !

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 4, 2016, 9:04pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/2 "2016-03-04T21:04:35Z")

</div>

Thanks for this guide.  
I have made it 2 days ago and i have this :  
Any idea ?

 ![](https://global.discourse-cdn.com/meta/original/3X/a/5/a51c002cf0398818a047ef7cf281c976028fada3.png)

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [March 4, 2016, 9:13pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/3 "2016-03-04T21:13:58Z")

</div>

Check this screenshot, the infos on mailgun are not made for Digital Ocean :

[![](https://global.discourse-cdn.com/meta/original/3X/8/1/81b6ead7d25f6306ea919b8bd34c2e817f3bb240.jpg) ](https://global.discourse-cdn.com/meta/original/3X/8/1/81b6ead7d25f6306ea919b8bd34c2e817f3bb240.jpg)

The first TXT with `@` instead of `wikidot.es` (and the commas `""` between `v=spf1 include:mailgun.org ~all`) should do the trick. I think the CNAME can only be validated if the two TXT are OK.

On the zone file you should have something like this at the end :

```
wikidot.es. 1800 IN TXT "v=spf1 include:mailgun.org ~all"
mailo._domainkey.wikidot.es. 1800 IN TXT "k=rsa; p=MIGf..."
email.wikidot.es. 1800 IN CNAME mailgun.org.

```

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 4, 2016, 9:17pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/4 "2016-03-04T21:17:01Z")

</div>

Yes , i have seen it and edited . Now i think  
i need to wait for propagate , true ?

 ![](https://global.discourse-cdn.com/meta/original/3X/8/9/89e5c1ebe334c1789d24819d2b57b5644d6cc690.png)

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [March 4, 2016, 9:20pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/5 "2016-03-04T21:20:20Z")

</div>

You don’t have to add `wikidot.es` in the second **TXT** , it didn’t work when i put `iunctis.fr` in mine, It worked only when I wrote : `mailo._domainkey`.

When my config was right, it was pretty quick. Less than 10 minutes.

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 4, 2016, 9:24pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/6 "2016-03-04T21:24:42Z")

</div>

> [@Steven](#):
>
> mailo.\_domainkey

Ok , done , so , the mailgun give the a bad config ? 😃

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 4, 2016, 9:26pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/7 "2016-03-04T21:26:12Z")

</div>

We don’t recommend letting DNS go to Digital Ocean. I discourage this whenever I see it, since for most people it is much simpler to control DNS from the same place they purchased the domain name from.

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 4, 2016, 9:32pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/8 "2016-03-04T21:32:00Z")

</div>

@codinghorror yes , i understand but in my register  
only i have option for create Glue Records , nothing else . ☹

 ![](https://global.discourse-cdn.com/meta/original/3X/0/d/0d3d88f42dd7549b21bf04a023e49d5d8f1d1bab.png)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 4, 2016, 10:25pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/9 "2016-03-04T22:25:41Z")

</div>

Sure in that case fine, but I’d be very hesitant to hand over DNS to Digital Ocean unless you have a very good reason. It’s less confusing and clearer to have your DNS handled in one place, the first place you bought the domain from, versus splitting DNS between two sources ..

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 5, 2016, 7:17pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/10 "2016-03-05T19:17:44Z")

</div>

@Steven  
If i am using cloudflare , where i need to add that lines ? On cloudflare dns panel or digitalocean dns panel ?

 ![](https://global.discourse-cdn.com/meta/original/3X/7/0/70b293460a2e018edc94bfc27e078613ce57bd1b.png)

On SPF field , the commas are not accepted 🙂

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [March 5, 2016, 9:56pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/11 "2016-03-05T21:56:56Z")

</div>

The commas are mostly for DO, it should work without it in Cloudfare

The line before that, it’s not SPF but **TXT** you have to use

---

<div class="post-metadata">

### Author: ![djcyry](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/djcyry/32/161664_2.png) [@djcyry](https://meta.discourse.org/u/djcyry)
#### Post date: [March 5, 2016, 10:35pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/12 "2016-03-05T22:35:56Z")

</div>

So , i need to change the SPF line into a TXT line ?

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [March 5, 2016, 10:57pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/13 "2016-03-05T22:57:37Z")

</div>

Yes, and I think it will be ok.

But I never tried with cloudfare so I can’t be 100% sure

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [March 6, 2016, 7:26am UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/14 "2016-03-06T07:26:08Z")

</div>

I’m guessing that Cloudflare automatically converted the TXT into an SPF record.

---

<div class="post-metadata">

### Author: ![Nick\_Putman](https://avatars.discourse-cdn.com/v4/letter/n/b5ac83/32.png) [@Nick\_Putman](https://meta.discourse.org/u/Nick_Putman)
#### Post date: [August 19, 2016, 12:44pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/15 "2016-08-19T12:44:56Z")

</div>

I am wondering what the correct settings are for subdomains. I currently have:

```
TXT: forum.open-dialogue.net - v=spf1 include:mailgun.org ~all
TXT: mailo._domainkey.forum.open-dialogue.net - k=rsa.....
CNAME: email.forum.open-dialogue.net - mailgun.org.

```

These are the settings recommended by Mailgun, and I have entered them in Digital Ocean. Because I am using a subdomain for discourse, I’m unsure if these are the right settings.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 19, 2016, 8:04pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/16 "2016-08-19T20:04:48Z")

</div>

You should include the subdomain because MailGun recommends that, it is also how Discourse sets up defaults.

`forum.example.com` → mail is from → `noreply@forum.example.com`

So you are setting up and validating the `forum.example.com` domain for email _not_ the parent domain.

---

<div class="post-metadata">

### Author: ![dsanchez](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dsanchez/32/64161_2.png) [@dsanchez](https://meta.discourse.org/u/dsanchez)
#### Post date: [December 8, 2016, 3:04pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/17 "2016-12-08T15:04:38Z")

</div>

Hi, following your instructions and still the “k=rsa; p=MIG…” does not get verified.

Another question:

I have a droplet in digital ocean, I am pointing my domain **[mysite.com](http://mysite.com)** to my IP. In order to do the mailgun configuration I created another domain **[mail.mysite.com](http://mail.mysite.com)** to do this setup. Is this the correct way?

This is what I have under [mail.mysite.com](http://mail.mysite.com)

 ![](https://global.discourse-cdn.com/meta/original/3X/1/0/100b3a208dedab86c518d79a531e7e03311d92fe.png)

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [December 8, 2016, 5:11pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/18 "2016-12-08T17:11:23Z")

</div>

Sometimes the k=rsa can take quite some time, you can try with `smtp._domainkey` instead of `mailo._domainkey`

Also, nothing links your server to the droplet, you should have at least an **A** record, with `@` and the ip adress

Here is a full DNS records on a droplet :

 ![](https://global.discourse-cdn.com/meta/original/3X/4/a/4a9aa766c40940a4d5489a61397f0aa6a3b5e9fd.jpg)

If you already use your DNS provider to config some records, I think the best way is to also use it for the subdomain, it will be quicker and simpler (you just use what mailgun tells you, no need to change some things). And it will not impact your previous config

---

<div class="post-metadata">

### Author: ![dsanchez](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dsanchez/32/64161_2.png) [@dsanchez](https://meta.discourse.org/u/dsanchez)
#### Post date: [December 8, 2016, 5:38pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/19 "2016-12-08T17:38:23Z")

</div>

> [@Steven](#):
>
> If you already use your DNS provider to config some records, I think the best way is to also use it for the subdomain, it will be quicker and simpler (you just use what mailgun tells you, no need to change some things). And it will not impact your previous config

not sure if I follow you. So creating another domain (well, actually a sub-domain) in my droplet is not needed? all should be done under the [mydomain.com](http://mydomain.com)? I thought the suggestion was to use a [subdomain.mydomain.com](http://subdomain.mydomain.com)

thanks

---

<div class="post-metadata">

### Author: ![Steven](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steven/32/187890_2.png) [@Steven](https://meta.discourse.org/u/Steven)
#### Post date: [December 8, 2016, 7:38pm UTC](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590/20 "2016-12-08T19:38:55Z")

</div>

You can do it without creating a subdomain or using the networking panel on DigitalOcean yes.

The guide is just an alternative to link mailgun with DO instead of a DNS provider. Some people tried using DigitalOcean to do this and I wanted to help. But it’s not necessary at all

Sorry if the guide was confusing

[Next page](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590.md?page=2)
