# 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:** [2016 年 3 月 4 日午後 7:57 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:** 1
**Showing post:** 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: [2016 年 3 月 4 日午後 7:57 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 !

---

_[View the full topic](https://meta.discourse.org/t/configure-mailgun-for-email-when-using-digital-ocean-for-dns/40590)._
