What Are MX Records?
MX (Mail eXchange) records are DNS records that tell the internet where to send email for your domain. When someone sends you mail@yourdomain.com, their mail server looks up your MX record to find your mail server's hostname or IP, then delivers the message there. Without correct MX records, your domain won't receive email at all.
How Email Routing Works
- Sender composes an email to user@yourdomain.com and hits send
- The sender's mail server queries DNS for yourdomain.com's MX records
- The sender's server looks up the hostname in the MX record (e.g., mail.yourdomain.com)
- The sender's server resolves that hostname to an IP address
- The sender's server connects to your mail server at that IP
- The email is delivered and stored until the recipient retrieves it
This happens in seconds—usually without the sender or recipient noticing.
MX Record Basics
An MX record has two key parts: a hostname (where mail goes) and a priority (which server is preferred).
Example MX record:
yourdomain.com MX 10 mail.yourdomain.com
yourdomain.com MX 20 mail2.yourdomain.com
Breaking this down:
yourdomain.com— The domain that receives mail (usually left as@or blank in DNS interfaces)MX— Record type (Mail eXchange)10— Priority (lower number = higher priority; 10 is preferred over 20)mail.yourdomain.com— Hostname of the mail server
Priority Numbers
Priorities let you set up failover. If your primary mail server goes down, the sender's server tries the next highest priority:
- Priority 10 (primary): Main mail server—try this first
- Priority 20 (secondary): Backup mail server—try if primary fails
- Priority 30 (tertiary): Third backup—try if primary and secondary fail
Lower numbers have higher priority. It's common to use 10, 20, 30 for clarity, but any numbers work (5 and 10, or 100 and 200, are equally valid).
Setting Up MX Records
Step 1: Determine Your Mail Server
Before adding an MX record, know where your email is hosted:
- Hosted mail with your hosting provider: Ask your provider for the mail server hostname (often
mail.yourdomain.comor a generic name likemail.example.com) - Google Workspace, Microsoft 365, or third-party email service: The service provides the MX record values to add
- Self-hosted mail server: Your own server hostname (you must have a valid A/AAAA DNS record for it too)
Step 2: Add the MX Record to DNS
- Log in to your DNS provider (usually your hosting control panel)
- Navigate to DNS Records or Zone Management
- Create a new MX record
- Leave the hostname blank or enter
@(this applies to your domain root) - Enter the mail server hostname in the "Value" or "Mail Server" field
- Enter the priority number (start with
10for your primary server) - Save the record
If your DNS interface requires one field per priority, add multiple MX records:
| Type | Name | Priority | Value |
|------|------|----------|-------|
| MX | @ | 10 | mail.yourdomain.com |
| MX | @ | 20 | mail2.yourdomain.com |
Step 3: Verify the Mail Server Hostname
Your MX record must point to a hostname (not an IP). That hostname must resolve to an IP via an A or AAAA record. Most hosting providers set this up automatically, but verify:
nslookup mail.yourdomain.com
You should see an IP address like 192.0.2.1. If it returns "not found," ask your hosting provider to add the A record.
Step 4: Test Your MX Records
After DNS propagation (usually within a few hours, up to 24), verify:
nslookup -type=MX yourdomain.com
You should see your MX record(s) listed with priorities in order.
Or use an online MX checker tool.
Step 5: Send a Test Email
Send an email to yourself or another account on your domain from an external address (e.g., a Gmail account). If it arrives, your MX record is working.
Common MX Record Issues
"No MX Records Found"
Problem: The domain has no MX records at all.
Cause: They weren't created, or they were deleted accidentally.
Fix: Add MX records following the steps above. Once added, allow up to 24 hours for global DNS propagation.
"MX Points to Invalid Hostname"
Problem: The MX record points to a hostname that doesn't have an A record.
Example:
CODE3
Fix: Verify the mail server hostname has a valid A or AAAA record:
CODE4
If it fails, ask your hosting provider to add the A record, or change the MX to point to a hostname that exists.
"MX Points to an IP Address"
Problem: MX records must not point to IP addresses directly.
Wrong:
CODE5
Right:
CODE6
Fix: Change the MX record to point to the mail server's hostname instead.
Multiple MX Records with Same Priority
Problem: If multiple servers have the same priority number, behavior is unpredictable.
Fix: Use different priority numbers for each server (10, 20, 30, etc.).
Old MX Records Still Present
Problem: Leftover MX records from a previous mail server cause confusion.
Fix: Delete any MX records you're no longer using. Most domains should have 1–3 MX records; more is unusual.
MX Records and Other Email Services
Using Third-Party Email (Google Workspace, Microsoft 365, etc.)
If you use a third-party email service, replace your MX records with theirs:
Before (self-hosted or hosting provider):
CODE7
After (Google Workspace example):
CODE8
The service provides all MX records; add them exactly as specified.
Migrating Email Services
When switching email providers:
- Add the new provider's MX records first (with lower priority numbers than the old ones)
- Wait a day or two for DNS propagation
- Once all mail is flowing through the new provider, delete the old MX records
- This ensures no mail is lost during the switch
Subdomain Email
You can route email to subdomains too:
mail.yourdomain.com MX 10 mail-server.yourdomain.com
This allows user@mail.yourdomain.com to be delivered separately from user@yourdomain.com.
Best Practices
- Use 2–3 MX records minimum: Set up a primary and at least one backup for redundancy
- Clearly number priorities: Use 10, 20, 30 (not 1, 2, 3) to make priorities obvious
- Remove old records: Delete MX records from previous mail servers to avoid confusion
- Test after changes: Send test emails to verify mail still arrives after any MX change
- Document your setup: Note which server is primary and why, especially if managing multiple domains
- Monitor mail logs: If mail stops arriving, check your mail server logs and MX records first
Combining MX with SPF, DKIM, and DMARC
MX records tell senders where to deliver email, while SPF/DKIM/DMARC tell them whether to trust it:
- MX: "Send mail to mail.yourdomain.com"
- SPF: "Mail from 192.0.2.1 is authorized"
- DKIM: "Emails signed by mail.yourdomain.com are legitimate"
- DMARC: "If SPF/DKIM fails, reject the email"
All four work together for complete email delivery and security.
When to Contact Your Hosting Provider
- You need to know the correct mail server hostname
- Email stops arriving after you change your MX record
- You're unsure whether your mail server has a valid A record
- You want to set up multiple MX records for redundancy
- Your old mail server MX record is still active and causing mail confusion