MX Records Explained: How Email Finds Its Destination
Technical

MX Records Explained: How Email Finds Its Destination

Alex Chen

Alex Chen

December 28, 2025

10 min read

A comprehensive technical guide to Mail Exchange (MX) records and how they route email traffic across the internet.

Introduction

When you send an email to someone@example.com, how does the internet know which server should receive that message? The answer lies in MX (Mail Exchange) records—a critical component of the Domain Name System (DNS) that directs email traffic to the correct mail servers.

Email Routing Flow

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Sender's Mail  │     │   DNS Server    │     │ Recipient's Mail│
│     Server      │     │                 │     │     Server      │
└────────┬────────┘     └────────┬────────┘     └────────┬────────┘
         │                       │                       │
         │  1. Query MX record   │                       │
         │  for example.com      │                       │
         │──────────────────────>│                       │
         │                       │                       │
         │  2. Return MX:        │                       │
         │  mail.example.com     │                       │
         │<──────────────────────│                       │
         │                       │                       │
         │  3. Connect to mail.example.com               │
         │──────────────────────────────────────────────>│
         │                       │                       │
         │  4. Deliver email via SMTP                    │
         │──────────────────────────────────────────────>│
         │                       │                       │

What Are MX Records?

MX records are DNS resource records that specify the mail servers responsible for accepting email on behalf of a domain. Unlike A records that point to IP addresses for web servers, MX records point to hostnames of mail servers.

MX Record Structure

An MX record consists of two main components:

ComponentDescriptionExample
PriorityLower number = higher priority10
Mail ServerHostname of the mail servermail.example.com

Example MX Configuration

dns
example.com.    IN    MX    10    mail1.example.com.
example.com.    IN    MX    20    mail2.example.com.
example.com.    IN    MX    30    backup.example.com.

How MX Lookup Works

When a mail server needs to deliver an email, it performs the following steps:

Step 1: DNS Query

The sending server queries DNS for the MX records of the recipient's domain:

bash
$ dig MX example.com

;; ANSWER SECTION:
example.com.    3600    IN    MX    10 mail1.example.com.
example.com.    3600    IN    MX    20 mail2.example.com.

Step 2: Priority Sorting

The server sorts MX records by priority (lowest number first) and attempts delivery to each server in order.

Step 3: A/AAAA Record Resolution

For each MX hostname, the server resolves the corresponding A (IPv4) or AAAA (IPv6) record to get the actual IP address.

Step 4: SMTP Connection

The sending server establishes an SMTP connection to the resolved IP address on port 25.

MX Priority and Failover

The priority system provides built-in redundancy:

Priority 10: mail1.example.com (Primary)
    ↓ If unavailable
Priority 20: mail2.example.com (Secondary)
    ↓ If unavailable
Priority 30: backup.example.com (Backup)

Load Balancing with Equal Priorities

When multiple MX records have the same priority, mail servers should distribute connections randomly:

dns
example.com.    IN    MX    10    mail1.example.com.
example.com.    IN    MX    10    mail2.example.com.
example.com.    IN    MX    10    mail3.example.com.

Common MX Configurations

Single Server Setup

dns
example.com.    IN    MX    10    mail.example.com.
mail.example.com.    IN    A    192.168.1.100

Google Workspace

dns
example.com.    IN    MX    1     ASPMX.L.GOOGLE.COM.
example.com.    IN    MX    5     ALT1.ASPMX.L.GOOGLE.COM.
example.com.    IN    MX    5     ALT2.ASPMX.L.GOOGLE.COM.
example.com.    IN    MX    10    ALT3.ASPMX.L.GOOGLE.COM.
example.com.    IN    MX    10    ALT4.ASPMX.L.GOOGLE.COM.

Microsoft 365

dns
example.com.    IN    MX    0    example-com.mail.protection.outlook.com.

MX Record Best Practices

1. Always Have Backup MX Servers

A single point of failure can cause email loss. Configure at least two MX records with different priorities.

2. Use Reasonable TTL Values

Production: 3600 seconds (1 hour)
During migration: 300 seconds (5 minutes)

3. Ensure A Records Exist

Every hostname in an MX record must have a corresponding A or AAAA record.

4. Don't Point MX to CNAME

RFC 2181 prohibits MX records from pointing to CNAME records. Always use A/AAAA records.

dns
# WRONG
example.com.    IN    MX    10    mail.example.com.
mail.example.com.    IN    CNAME    mailserver.provider.com.

# CORRECT
example.com.    IN    MX    10    mail.example.com.
mail.example.com.    IN    A    203.0.113.10

Troubleshooting MX Records

Common Issues

ProblemCauseSolution
Email not deliveredMissing MX recordAdd MX record
Intermittent deliveryDNS propagationWait for TTL expiry
Bounced emailsInvalid MX hostnameVerify A record exists
Connection refusedFirewall blockingOpen port 25

Diagnostic Commands

bash
# Check MX records
dig MX example.com +short

# Verify mail server is reachable
telnet mail.example.com 25

# Full DNS trace
dig MX example.com +trace

MX Records and Email Security

MX records work alongside other DNS records for email security:

SPF: Specifies which servers can send email for your domain
DKIM: Cryptographically signs outgoing emails
DMARC: Defines policy for handling authentication failures

Together, these records form a comprehensive email authentication framework.

Conclusion

MX records are the foundation of email routing on the internet. Understanding how they work is essential for:

Setting up email for your domain
Troubleshooting delivery issues
Planning for high availability
Migrating email providers

Proper MX configuration ensures your emails reach their destination reliably and efficiently.