Mailgun Setup
Mailgun is a transactional email API service that enables you to send emails from your website or application. This guide will walk you through setting up a Mailgun sending domain for your Django project.
Prerequisites
Following our previous guide, you should have a functioning domain, such as https://interviewdb.com. However, we still need to verify it with Mailgun.
Create a Mailgun Account
If you don't already have a Mailgun account, you can sign up for one here.
Add and Verify Your Domain
After creating your account, you'll need to add and verify your domain. To do this, go to the Mailgun Domains page and click the "Add New Domain" button.
Use the exact DNS records that Mailgun shows you for your domain. Depending on your Mailgun configuration, this usually includes an SPF TXT record, DKIM records, and sometimes tracking / return-path CNAMEs. If you also want Mailgun to receive email for that domain, Mailgun will additionally ask you to add MX records.
- Navigate to your Namecheap domain dashboard and select the "Manage" button next to the domain you wish to use with Mailgun.
- Proceed to the "Advanced DNS" tab.
- Add each DNS record exactly as Mailgun presents it in the dashboard.
- For SPF, you will usually create a
TXTrecord at the root host such as@, with a value similar tov=spf1 include:mailgun.org ~all. - For DKIM, Mailgun may give you either
TXTorCNAMErecords, depending on the domain settings shown in your account.
DKIM
Mailgun commonly provides one or more DKIM selectors such as k1._domainkey. Use the exact host and value shown in the Mailgun dashboard for your domain.
Next, navigate to the top of the page and click on the Verify DNS settings button to initiate the verification of your DNS records. This verification may take a few minutes. Upon successful verification, a green checkmark will appear next to your domain.
If you use Cloudflare, keep Mailgun verification records on DNS only during verification. Proxied DNS can prevent Mailgun from seeing the real DNS target values.
Note: Add the optional MX records only if you want Mailgun to receive mail for that domain. For simple transactional sending, the records shown in your sending-domain setup are the important ones.