MX Records: How They Direct Your Email Traffic
Mail Exchange (MX) records are a type of DNS record that specify which mail servers are responsible for accepting email on behalf of your domain. Understanding MX records is essential for setting up and maintaining email services for your domain.
What is an MX Record?
An MX record is a type of resource record in the Domain Name System (DNS) that specifies a mail server responsible for accepting email messages on behalf of a domain name. It points to a domain name, not an IP address.
MX Record Format
An MX record has two main components:
- Priority value: A number that indicates the preference for mail delivery. Lower values have higher priority.
- Mail server hostname: The fully qualified domain name of the mail server.
Example MX record format:
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.
How MX Records Work
When someone sends an email to user@example.com, the sending mail server performs a DNS lookup for MX records of example.com. The server then attempts to deliver the email to the mail server with the lowest priority value (highest priority). If that server is unavailable, it tries the next one in order of priority.
Multiple MX Records
Most domains have multiple MX records for redundancy. If one mail server is down, email can still be delivered to another server. MX records with the same priority value indicate that the sending server can choose any of them randomly.
Common MX Configurations
Self-Hosted Email
If you run your own mail server:
example.com. IN MX 10 mail.example.com.
Google Workspace (formerly G Suite)
If you use Google for your email:
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
If you use Microsoft 365 for your email:
example.com. IN MX 0 example-com.mail.protection.outlook.com.
Best Practices for MX Records
Use Multiple MX Records
Always have at least two MX records pointing to different mail servers for redundancy.
Set Appropriate Priority Values
Use priority values that reflect your intended mail flow. Primary servers should have lower values than backup servers.
Ensure Proper A/AAAA Records
Make sure that each mail server referenced in an MX record has corresponding A or AAAA records in DNS.
Regular Verification
Periodically verify that your MX records are correctly configured and that all mail servers are operational.
Avoid Using an IP Address
MX records must point to a domain name, not an IP address. The domain name should then have an A or AAAA record pointing to the server's IP address.
Troubleshooting MX Records
Common Issues
- Missing or incorrectly configured MX records
- Mail servers that are unreachable or not accepting connections
- Incorrect priority values causing traffic to go to the wrong server
- Outdated records pointing to decommissioned servers
Testing Tools
Several tools can help you verify your MX records:
- Command-line tools like
dig
ornslookup
- Online MX record lookup tools
- Email deliverability testing services
Conclusion
MX records are a critical component of your domain's email infrastructure. Proper configuration ensures reliable email delivery and helps prevent email delivery issues. Regular monitoring and maintenance of your MX records should be part of your domain management routine.