MX Record Verification: How It Works and Why It's Essential
Syntax checks lie. A perfectly formatted email can belong to a domain that hasn't been able to receive mail in years. MX record verification is how you find out the truth.
MailSentry Team
Email validation experts
TL;DR
- •MX records are DNS entries that specify which mail servers accept email for a domain — without them, no email can be delivered regardless of address syntax.
- •MX verification sits between syntax checking and SMTP verification in the validation pipeline, catching fabricated and misconfigured domains that syntax alone misses.
- •Node.js can resolve MX records in milliseconds using the built-in dns module, making it lightweight enough for real-time validation during form submission.
When you validate an email address, syntax checking is only the first gate. An address like user@perfectly-formatted-but-fake-domain.com will pass every regex in existence, yet no email will ever reach it because the domain does not exist or cannot receive mail. MX record verification closes this gap by querying the Domain Name System to confirm that the domain behind an email address is configured to accept messages.
What Are MX Records?
MX stands for Mail Exchanger. An MX record is a type of DNS resource record that specifies which mail server is responsible for accepting email on behalf of a domain. When a sending mail server wants to deliver a message to user@example.com, it performs a DNS lookup for the MX records of example.com. The response contains one or more hostnames, each with a priority value:
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.
The sending server tries the lowest-priority (highest-preference) host first. If that server is unreachable, it falls back to the next one. This mechanism provides redundancy and load balancing for inbound email.
Why MX Verification Matters
Without an MX check, your validation pipeline has a significant blind spot:
- Catch fabricated domains. Users who enter random strings as domains — intentionally or accidentally — are stopped before they pollute your database.
- Detect expired or parked domains. A domain may resolve to an IP address (it has an A record) but not accept email (no MX records). MX verification distinguishes between web-only domains and those configured for mail.
- Reduce bounces. Sending to a domain with no mail server guarantees a hard bounce. Catching these addresses upfront protects your sender reputation.
- Improve data quality. Knowing that a domain can receive mail is a strong signal that the address is at least plausible, even before you verify the individual mailbox.
Solve this with MailSentry
8 validation layers, real-time results, sub-50ms response.
Try MailSentry Free →Implementing MX Verification in Node.js
Node.js ships with a built-in dns module that can resolve MX records directly:
import dns from "node:dns/promises";
async function hasMxRecords(domain: string): Promise<boolean> {
try {
const records = await dns.resolveMx(domain);
return records.length > 0;
} catch (error: any) {
// ENOTFOUND — domain does not exist
// ENODATA — domain exists but has no MX records
return false;
}
}
// Usage
const domain = "gmail.com";
const canReceiveMail = await hasMxRecords(domain);
console.log(`${domain} can receive mail: ${canReceiveMail}`);
// gmail.com can receive mail: true
This function resolves in milliseconds for cached domains and typically under 200ms for uncached lookups. It is lightweight enough to call during a synchronous form submission without noticeably degrading the user experience.
Edge Cases to Handle
Implicit MX (A Record Fallback)
RFC 5321 specifies that if a domain has no MX records but does have an A or AAAA record, the sending server should attempt delivery directly to that host. In practice, most modern mail infrastructure ignores this fallback, but if you want strict compliance you can add an A record check as a secondary signal:
async function canReceiveMail(domain: string): Promise<boolean> {
try {
const mx = await dns.resolveMx(domain);
if (mx.length > 0) return true;
} catch {}
try {
const a = await dns.resolve4(domain);
return a.length > 0; // implicit MX via A record
} catch {}
return false;
}
Null MX
Some domains explicitly declare that they do not accept email by publishing a null MX record (a single MX record with a priority of 0 and an empty hostname, specified in RFC 7505). If you encounter this, treat the domain as unable to receive mail.
Timeouts and Transient Failures
DNS lookups can time out due to network conditions or overloaded nameservers. Treat transient failures gracefully — do not reject the address outright. Instead, accept it provisionally and flag it for re-verification later.
Where MX Checks Fit in the Pipeline
MX verification sits between syntax validation and mailbox-level SMTP verification in a typical email validation pipeline:
- Syntax check — Is the address well-formed?
- MX record check — Can the domain receive mail?
- SMTP verification — Does the specific mailbox exist?
Running them in this order is efficient because each step is more expensive than the last. Syntax checking is instantaneous, MX lookups take milliseconds, and SMTP verification requires a network handshake with a remote server. By filtering out bad syntax and dead domains early, you minimize the number of costly SMTP checks.
Services like MailSentry run all three layers in a single API call, returning the results in a unified response so you do not have to orchestrate the pipeline yourself.
Key Takeaways
MX record verification is a fast, reliable, and essential layer in any email validation pipeline. It catches fabricated and misconfigured domains that syntax checks miss, reduces hard bounces, and improves overall data quality. Implementing it in Node.js requires only a few lines of code using the built-in DNS module, and it integrates naturally between syntax validation and SMTP verification for a defense-in-depth approach.
Try MailSentry Free
8 validation layers, sub-50ms response, 1,000 checks/month free.
Get Your Free API Key →