A synopsis of how to setup email to work with MailGun and DigitalOcean, and some links for more detailed instructions.
I am assuming you have both a mailgun and digitalocean account and you have created a droplet with a domain name and digitalocean will manage the DNS servers for that domain name. In this example my domain name is lucidastrology.com (registered at namecheap.com and managed by digitalocean).
MailGun Setup
Login to your mailgun account and go to the Domains page. https://app.mailgun.com/app/domains
Add a new domain with a subdomain for email. i.e. mg.lucidastrology.com
After the domain is created, click the domain name link in the list of domain names. This will show all the mailgun settings that will make your email work for that domain. On that page, go to the section with the heading Domain Verification & DNS. Here you will find values for TXT, MX, and CNAME records. These are the values you need to copy to your digitalocean DNS records.
DigitalOcean Setup
On digitalocean go to the project page for your droplet. Click the Networking link in the left side menu. Under the Add a domain heading, enter a domain name with the exact same name as the domain name you created in your mailgun account (mg.lucidastrology.com). Associate the new domain with the appropriate project. Click the ‘Add Domain’ button.
This will take you to a new page with the DNS settings for the new domain. Under the Create new record heading are tabs for each of the record types. This is where you need to create a new record for each mailgun value, so select the appropriate tab for the record you want to create (TXT, MX, CNAME).
Creating the DNS Records
You need to copy the DNS record information from mailgun to digitalocean.
On digitalocean click the TXT tab. In the box labeled VALUE, paste or type the value from under the heading Enter This Value on mailgun. For the HOSTNAME on digitalocean, enter @ if the mailgun domain value is exactly the same as the domain name you created for this email account (ie. mg.lucidastrology.com). If there is additional information on the domain name at mailgun (i.e. k1._domainkey from k1._domainkey.mg.lucidastrology.com), copy and paste ONLY the additional information (without the ending period) to the digitalocean hostname. Then click the ‘Create Record’ button. Create as many TXT records on digitalocean as there are on mailgun.
For the MX records on digitalocean, enter @ for the HOSTNAME value. Then copy the value under the mailgun label Enter This Value and paste it into the box under the label MAIL PROVIDERS MAIL SERVER on digitalocean. Enter the same priority value as shown in mailgun. Click the ‘Create Record’ button. Do this for all MX records on mailgun.
For the CNAME record, copy the additional information from the Hostname domain name at mailgun (i.e. email from email.mg.lucidastrology.com), and paste it into the digitalocean hostname. Then copy the value under the mailgun label Enter This Value and paste it into the box under the label IS AN ALIAS OF on digitalocean. Click the ‘Create Record’ button.
Verify
On the same mailgun page, click the ‘Check DNS Records Now’ button located directly under the heading Domain Verification & DNS. This should show green check marks next to each record, or an error message. If it is all green you are good to go!
Sending eMail
How do I start sending email?: https://help.mailgun.com/hc/en-us/articles/202464990-How-do-I-start-sending-email-
The Python library: https://documentation.mailgun.com/en/latest/libraries.html#python
Sending email with Python: https://documentation.mailgun.com/en/latest/quickstart-sending.html#how-to-start-sending-email
More Detailed Instructions from DigitalOcean
More detailed instructions are here: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-mail-relay-with-postfix-and-mailgun-on-ubuntu-16-04
More information about creating DNS records: https://www.digitalocean.com/docs/networking/dns/how-to/manage-records/