Adding and Verifying a Domain in Mailgun


Adding and verifying a domain from within your Mailgun account is required in order to prove ownership of the domain from which outgoing messages will be sent. You must complete this step before configuring the Mailgun Integration within Gravity SMTP. This article outlines steps for both adding and verifying a domain in your Mailgun account. Reference Domain Verification Walkthrough from Mailgun’s official documentation for more info and related articles.

Adding a New Domain

From within your Mailgun account, navigate to Sending → Domains in the left sidebar and click Add new domain.

You will be presented with several settings to configure. Be sure to note the domain name and domain region you are setting here as they will be needed when connecting Gravity SMTP to your Mailgun account.

Enter a new domain name for the handling of emails via Mailgun. This must be a domain you own. Select a unique subdomain for delivery of messages from Mailgun. We agree with Mailgun’s recommendation to set a subdomain of mg so that you can uniquely identify this subdomain with the Mailgun service. We assume us of an mg subdomain through the rest of this setup documentation. Using a subdomain will still allow you to set a sending email address at the root domain.

Set a domain region from which messages will be sent. Mailgun supports sending messages from either US or EU.

If your account supports dedicated IPs, you can select a specific IP or an IP pool from which messages will be sent.

You can optionally set a longer DKIM key length for additional security. However, note that some nameserver tools do not support longer DKIM key lengths.

Having completed these settings, you can click the Add Domain button. This will immediately direct you to Sending → Overview screen for your new domain which will show domain verification instructions.

Verifying Your New Domain

In order to verify ownership of your domain and enable use of this domain with Mailgun, you will need to add multiple DNS records for the domain you have just added. Mailgun will run verification against five DNS records for your new subdomain. Your next step is to visit your DNS provider for this root domain and add each DNS record provided by Mailgun. Please note that all records are specific to the subdomain as indicated via the hostname value.

Mailgun provides detailed documentation on configuring these DNS records with the following common providers:

Adding DNS Records

SPF (Sender Policy Framework) records for sending exist as a TXT record and are designed to prevent email spoofing. They specify which mail servers are permitted to send email on behalf of your domain, improving email delivery accuracy and preventing your domain from being used for phishing or spam.

TXTmgv=spf1 ~all3600

DKIM (DomainKeys Identified Mail) records for sending exist as a TXT record and are used to authenticate emails, confirming messages are actually from the domain they claim to be from and have not been tampered with during transmission. This enhances email security, mitigates the risk of email spoofing, and increases the likelihood of legitimate emails reaching their intended recipients.

TXTThis hostname will be unique.This value will be unique.3600

MX (Mail Exchange) records for receiving designate the mail server responsible for accepting email messages on behalf of a domain. They direct sending mail servers on where to route emails for a specific domain, ensuring that messages are delivered to the correct destination.

TypeHostnamePriorityValue/Mail ServerTTL

CNAME (Canonical Name) records map an alias name to a true or canonical domain name. They’re used to link a subdomain to another domain name, allowing requests made to the alias to be routed to the correct server or site.

TypeHostnameValue/Target NameTTL

Verifying DNS Settings

After having added all DNS records for the domain, you will then click the Verify DNS Settings in the upper right of the page. It can take time for DNS records to propagate. Mailgun will send you an email once the domain records have been verified and your subdomain is ready to handle messages.

You can view the status of your domain verification by going to Sending → Domains within your Mailgun account. Once verified, DNS records for a domain can be accessed by navigating to Sending → Domain settings → DNS Records for the specific domain.

Once all records are verified, you are ready to get your API key.