technical · sourced answer

How to Check if an Email Domain is Valid

To check if an email domain is valid, perform a DNS lookup for Mail Exchanger (MX) records to confirm the domain is configured to receive email. A domain is considered valid for email if it has at least one active MX record pointing to a mail server. If no MX records exist, the domain cannot receive email unless it falls back to an A record, though this is uncommon in modern setups.

Syntax Validation

The first step is verifying the domain follows RFC 5322 standards. The domain part of an email address must contain a top level domain and follow specific character rules. Use regular expressions to ensure there are no illegal characters or consecutive dots before attempting a network request. This prevents unnecessary DNS queries for obviously malformed strings.

MX Record Lookup

Perform a DNS query for the MX record of the domain. An MX record specifies the mail server responsible for accepting email messages on behalf of the domain. If the DNS query returns one or more valid MX records, the domain is technically capable of receiving mail. Tools like dig or nslookup can be used for manual verification, while programming libraries provide asynchronous methods for bulk checks.

A Record Fallback

According to SMTP standards, if no MX record is present, a sending server may attempt to deliver mail to the IP address specified in the A record of the domain. While this is a legacy behavior, checking for an A record provides a secondary layer of validation. However, the absence of both MX and A records confirms the domain is invalid for email delivery.

Verification Tools

For developers implementing this at scale, using a dedicated validation service is more efficient than managing raw DNS queries. SendHQ provides free tools at https://sendhq.cc/tools to help verify domain configurations. These tools automate the lookup process and check for common misconfigurations that might lead to delivery failures.

Handling DNS Failures

Distinguish between a NXDOMAIN response and a timeout. A NXDOMAIN response explicitly indicates the domain does not exist. A timeout or SERVFAIL may indicate a temporary DNS issue or a restrictive firewall. Implement a retry logic with exponential backoff for non definitive errors to avoid marking valid domains as invalid during transient network outages.

Questions teams ask

Does a valid MX record guarantee the email address exists?

No, an MX record only confirms the domain can receive mail. It does not verify that a specific mailbox or user exists on that server.

Can a domain be valid without an MX record?

Yes, if the domain has an A record, some SMTP servers will attempt delivery to that IP, though this is not the standard practice for modern mail.

What is the difference between domain validation and email validation?

Domain validation checks if the domain is configured for mail, while email validation checks the specific address syntax and domain status.

Primary sources