Suped

How can I bulk check and clean MX records for a list of domains?

Published 10 Jul 2025
Updated 27 Nov 2026
18 min read
Summarize with
Bulk MX record checking and cleanup workflow for a list of domains.
Updated on 27 Nov 2026: We clarified bulk MX classification, corrected the CSV script, and added steps for repairing MX records on domains you manage.
Yes. For a list of hundreds or thousands of domains, a bulk DNS MX lookup is a practical first pass, followed by a cleanup step that classifies each domain into keep, suppress, retry, or review. Start with dig -t MX -f domains.txt because it can read a file of domains directly and return the raw MX answers without sending any mail. MX (Mail Exchange) records identify the mail server hostnames for incoming email; DNS resolution does not confirm that those servers are accepting SMTP connections.
No MX record is not always the same as no mail route. SMTP delivery falls back to the domain's A or AAAA record when there is no MX. Treat that as a review category, not an automatic delete. A valid null MX record and NXDOMAIN are much stronger suppression signals. SERVFAIL, REFUSED, and timeouts are temporary or indeterminate results that belong in a retry queue.
  1. Fast pass: Normalize and deduplicate domains, run a bulk MX lookup, and keep the queried domain beside every answer.
  2. Clean pass: Separate usable MX, null MX, NXDOMAIN, implicit MX fallback, malformed targets, unusable targets, and temporary DNS failures while preserving every preference value.
  3. Final pass: Send only the remaining address list to address-level validation, then test the sending setup before mailing.

Use dig in batch mode for the first pass

Put one domain per line in a plain text file. Strip schemes, paths, ports, spaces, trailing dots, and email local parts first. Convert internationalized domain names to their ASCII form before the lookup. A clean input file matters because DNS tools do not know whether https://example.com/path is meant to be a domain, a URL, or dirty export data. Reject any value that does not pass the domain syntax rules used by the source database before querying DNS. Preserve the exact domain after @, including any subdomain. MX records are not inherited from a parent domain, so checking example.com does not validate an address at mail.example.com. Supply domain names only, not complete CSV rows.
domains.txttext
example.com example.net example.org example.invalid
Then run a bulk MX query. The -f option reads the file line by line, while -t MX sets MX as the query type for those lines. Use +noall +comments +question +answer for early investigation because the question section identifies the domain and the header preserves the DNS response status. The BIND dig manual documents batch input and output controls. dig is required for these commands; the CSV script also requires Bash and standard shell utilities.
Bulk MX lookupbash
dig -t MX -f domains.txt +noall +comments +question +answer > mx-answers.txt
Why short output fails during cleanup
The command dig domain MX +short is useful for one domain, but it becomes awkward when hundreds of domains are mixed together. Short output omits the response status and queried domain, so an empty result cannot distinguish no MX data from a failed query.
  1. For inspection: Keep the question section and response header so each result can be tied to the input domain.
  2. For parsing: Use a script that records the DNS status and writes one decision per normalized domain.

Clean the results into decisions

A valid MX answer is only one cleanup signal. The useful output is a decision table with the raw DNS result preserved. A script should not silently delete domains just because a DNS response was empty for one resolver at one moment.

DNS result

Meaning

Action

Usable MX
At least one MX target resolves directly to A or AAAA
Keep
Partial MX route
A direct target resolves, but another target or address lookup has a problem
Keep working route; review or retry failed checks
Valid null MX
Domain explicitly accepts no mail
Suppress
NXDOMAIN
Domain does not exist
Suppress
No MX, A or AAAA exists
Implicit MX fallback
Review
No MX, no A or AAAA
No mail route found after successful fallback lookups
Suppress only after confirmation
MX targets do not resolve
Published route is unusable
Review
SERVFAIL, REFUSED, or timeout
Temporary or indeterminate DNS result
Retry
Possible parked-domain MX
Hosting pattern that needs confirmation
Review current domain use and local policy
MX cleanup categories for domain-list hygiene.
Common DNS answerstext
example.com. 3600 IN MX 10 mx1.example.net. example.org. 3600 IN MX 0 .
The second line is the one people miss. A single MX record with preference 0 and a target of one dot is a null MX. It tells senders the domain accepts no mail. A null MX must not appear beside another MX record, so a mixed answer belongs in review rather than automatic suppression. This no-mail declaration is defined in RFC 7505.
If the answer looks unusual, investigate before deleting. Patterns such as parked-domain mail routes, typo domains, and old provider records are easier to spot when compared with known suspicious MX records. It also helps to understand how MX records impact bounces before suppressing a large slice of a database.
Do not treat no MX as one answer
No MX with an A or AAAA record creates an implicit MX route. That differs from NXDOMAIN and null MX. A published MX needs at least one target hostname that resolves directly to an A or AAAA address. A CNAME used as the MX target is a malformed route, even if following the alias eventually returns an address. If explicit MX records exist but every target fails, do not substitute the recipient domain's A or AAAA records. The fallback applies only when MX records are absent, as specified in RFC 5321. Keep implicit routes and malformed targets in review.

Interpret MX priority without dropping routes

MX preference is delivery order, not a quality score. Lower numbers have higher preference. SMTP clients try the preferred route first and can move to higher-numbered routes when delivery fails. Keep every MX hostname and preference in the export, because saving only the first record can hide a working fallback or a partial configuration error.

MX pattern

What it means

Cleanup treatment

Different preference values
Lower numbers are tried first
Store every route in order
Equal preference values
Senders normally randomize equally preferred routes
Keep them together
CNAME target
The MX points to an alias instead of an address-bearing host
Mark malformed and review
Some targets resolve
The domain has a partial mail route
Keep the working route and review
How MX routing details affect a cleanup decision.
TTL is a cache lifetime, not a health score. Record the MX TTL and check time so reviewers know when the snapshot can become stale. After a DNS change, account for the previous record's cached TTL. NXDOMAIN and NOERROR responses without MX data (NODATA) can also be cached. Their negative-cache lifetime comes from the zone's SOA record, as described in RFC 2308, so a newly added MX record does not immediately replace a cached negative answer.
  1. Preserve all routes: Export each hostname with its numeric preference instead of keeping only the lowest value.
  2. Resolve targets directly: Flag an MX target that answers through a CNAME, even when the alias ultimately has an address.
  3. Separate partial failure: Do not equate one broken target with a domain whose entire published route is unusable.
  4. Recheck active lists: Run fresh DNS checks before a material send or after the list has sat unused.

Separate permanent and temporary DNS failures

An empty answer is not a cleanup status. NXDOMAIN reports that the queried name does not exist at lookup time; it does not mean the domain can never be registered or restored. NOERROR with no MX data is a NODATA result and needs A and AAAA fallback checks. SERVFAIL can indicate broken authoritative DNS or DNSSEC, while REFUSED and a timeout can come from resolver policy, rate limits, or network conditions.
  1. Retry separately: Queue SERVFAIL, REFUSED, and timeouts instead of mixing them with permanent failures.
  2. Control concurrency: Cap simultaneous lookups and back off when a resolver starts dropping requests.
  3. Cache by domain: Resolve each normalized domain once, then map the result back to every source row.
  4. Keep audit fields: Store the response status, MX targets, preferences, TTL, attempt count, resolver, and check time.
Retry temporary results at a slower rate and confirm persistent failures through another trusted recursive resolver. DNS caches can legitimately differ during record changes, so disagreement is a reason to review the row, not to choose the harsher result. Keep a working A or AAAA result when the other address family is unavailable, and flag the incomplete check. Never convert that partial failure into a confirmed no-route result.

A practical cleanup workflow

Bulk MX record cleanup flow from domain normalization through CSV export.
Bulk MX record cleanup flow from domain normalization through CSV export.
For a one-time list cleanup, use a staged workflow instead of one large delete rule. It keeps false suppressions low and makes the output easier to explain if a sales team, CRM owner, or data team asks why a domain was removed.
  1. Normalize: Lowercase domains, remove schemes and paths, retain only the domain after @, convert internationalized names to ASCII, and deduplicate while retaining a source-row key.
  2. Query: Run MX lookups with capped concurrency, timeouts, and retries so one slow resolver does not stall the batch.
  3. Classify: Write usable MX, partial MX, valid null MX, NXDOMAIN, implicit MX, malformed MX, unusable MX, no route, and retry statuses.
  4. Verify: Resolve MX targets directly to A or AAAA records and spot-check each suppression bucket.
  5. Export: Map each domain decision back to the original rows, preserving the reason, preference values, and DNS evidence.
For domains the team owns, DNS hygiene should not stop at recipient-domain cleanup. Suped's domain health checker checks published SPF, DKIM, and DMARC records. That is useful when the cleanup exposes owned domains that also need authentication work. The checker does not test MX-server availability, and its common-selector DKIM scan does not discover every signing key.
?

What's your domain score?

Deep-scan SPF, DKIM & DMARC records for email deliverability and security issues.

Keep the widget step separate from the raw bulk lookup. The lookup identifies recipient domains with a published DNS mail route. The domain health check inspects authentication records for domains under management. Use a real-message test to confirm authentication on sent email.
Domain health checker sample results showing DMARC, SPF, DKIM scorecards and detailed validation checks

Script a CSV you can review

The command-line pass is useful for discovery. For cleanup, use a CSV that can go back into a database or spreadsheet with a status column. This shell script expects syntax-checked ASCII domains, deduplicates them, and produces one row per domain. It preserves MX preference values, checks implicit MX fallback, flags CNAME targets, and separates partial MX routes from complete failures. It runs sequentially with one attempt per query; retry rows need a separate pass. Each lookup is saved in a generated evidence directory with its response header, answers, SOA data when returned, resolver, and timestamps.
mx-cleanup.shbash
#!/usr/bin/env bash set -u export LC_ALL=C if [ "$#" -gt 0 ]; then input="$1" else input=domains.txt fi if ! command -v dig >/dev/null 2>&1 || [ ! -r "$input" ]; then printf 'dig must be installed and the input file must be readable.\n' >&2 exit 1 fi work_file=$(mktemp) || exit 1 trap 'rm -f "$work_file"' EXIT evidence_dir=$(mktemp -d ./mx-evidence.XXXXXX) || exit 1 printf 'DNS evidence: %s\n' "$evidence_dir" >&2 lookup() { local query_name="$1" query_type="$2" reply_file reply_file=$(mktemp "$evidence_dir/query.XXXXXX") || exit 1 { printf ';; checked_at_utc: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" dig +time=2 +tries=1 -q "$query_name." -t "$query_type" \ +noall +comments +question +answer +authority +stats +class +ttlid 2>&1 } | tee "$reply_file" } normalize_domain() { sed -E ' s/^[[:space:]]+//; s/[[:space:]]+$//; s#^[A-Za-z]+://##; s#^[^@/]+@##; s#/.*$##; s/:[0-9]+$//; s/\.$// ' | tr '[:upper:]' '[:lower:]' } while IFS= read -r raw || [ -n "$raw" ]; do printf '%s\n' "$raw" | normalize_domain done < "$input" | awk 'NF && !seen[$0]++' > "$work_file" dns_status() { awk '/status:/ { gsub(/,/, "", $6) print $6 exit }' } has_type() { record_type="$1" awk -v t="$record_type" '$4 == t {found=1} END {exit !found}' } emit() { printf '"%s","%s","%s","%s"\n' "$1" "$2" "$3" "$4" } printf 'domain,status,dns_status,mx_hosts\n' while IFS= read -r domain; do mx_reply=$(lookup "$domain" MX) mx_status=$(printf '%s\n' "$mx_reply" | dns_status) if [ -z "$mx_status" ]; then emit "$domain" retry_no_response unknown "" continue fi if [ "$mx_status" = NXDOMAIN ]; then emit "$domain" nxdomain NXDOMAIN "" continue fi if [ "$mx_status" != NOERROR ]; then lower_status=$(printf '%s' "$mx_status" | tr '[:upper:]' '[:lower:]') emit "$domain" "retry_$lower_status" "$mx_status" "" continue fi mx_rows=$(printf '%s\n' "$mx_reply" | awk '$4 == "MX" {print $5, $6}' | sort -n -k1,1) mx_count=$(printf '%s\n' "$mx_rows" | awk 'NF {n++} END {print n+0}') valid_null=$(printf '%s\n' "$mx_rows" | awk '$1 == 0 && $2 == "." {n++} END {print n+0}') any_dot=$(printf '%s\n' "$mx_rows" | awk '$2 == "." {n++} END {print n+0}') mx_hosts=$(printf '%s\n' "$mx_rows" | awk ' NF { host=$2 if (host != ".") sub(/\.$/, "", host) printf "%s%s:%s", sep, $1, host sep=";" } ') if [ "$mx_count" -eq 1 ] && [ "$valid_null" -eq 1 ]; then emit "$domain" null_mx NOERROR "0:." continue fi if [ "$any_dot" -gt 0 ]; then emit "$domain" malformed_mx NOERROR "$mx_hosts" continue fi if [ "$mx_count" -gt 0 ]; then usable=false transient=false malformed=false incomplete=false while read -r preference host; do host=$(printf '%s' "$host" | sed 's/\.$//') a_reply=$(lookup "$host" A) aaaa_reply=$(lookup "$host" AAAA) a_status=$(printf '%s\n' "$a_reply" | dns_status) aaaa_status=$(printf '%s\n' "$aaaa_reply" | dns_status) target_malformed=false if printf '%s\n' "$a_reply" | has_type CNAME || printf '%s\n' "$aaaa_reply" | has_type CNAME then malformed=true target_malformed=true fi if [ "$target_malformed" = false ] && { { [ "$a_status" = NOERROR ] && printf '%s\n' "$a_reply" | has_type A; } || { [ "$aaaa_status" = NOERROR ] && printf '%s\n' "$aaaa_reply" | has_type AAAA; }; } then usable=true else incomplete=true fi if { [ -z "$a_status" ] || { [ "$a_status" != NOERROR ] && [ "$a_status" != NXDOMAIN ]; }; } || { [ -z "$aaaa_status" ] || { [ "$aaaa_status" != NOERROR ] && [ "$aaaa_status" != NXDOMAIN ]; }; } then transient=true fi done <<EOF $mx_rows EOF if [ "$usable" = true ]; then if [ "$malformed" = true ] || [ "$incomplete" = true ] || [ "$transient" = true ]; then emit "$domain" partial_mx NOERROR "$mx_hosts" else emit "$domain" has_usable_mx NOERROR "$mx_hosts" fi elif [ "$transient" = true ]; then emit "$domain" retry_dns_error temporary "$mx_hosts" elif [ "$malformed" = true ]; then emit "$domain" malformed_mx NOERROR "$mx_hosts" else emit "$domain" unusable_mx NOERROR "$mx_hosts" fi continue fi a_reply=$(lookup "$domain" A) aaaa_reply=$(lookup "$domain" AAAA) a_status=$(printf '%s\n' "$a_reply" | dns_status) aaaa_status=$(printf '%s\n' "$aaaa_reply" | dns_status) if { [ "$a_status" = NOERROR ] && printf '%s\n' "$a_reply" | has_type A; } || { [ "$aaaa_status" = NOERROR ] && printf '%s\n' "$aaaa_reply" | has_type AAAA; } then emit "$domain" implicit_mx NOERROR "" elif [ "$a_status" != NOERROR ] || [ "$aaaa_status" != NOERROR ]; then emit "$domain" retry_dns_error temporary "" else emit "$domain" no_mail_route NOERROR "" fi done < "$work_file"
Run the CSV exportbash
bash mx-cleanup.sh domains.txt > mx-results.csv
Run it against a copy of the export, not the production table. Convert internationalized names to ASCII before input; the script deliberately preserves valid subdomains such as www.example.com instead of rewriting them. Review counts by status before taking action. Join the result back through the normalized domain field so duplicate source rows and unrelated columns stay intact. A high number of implicit_mx or retry_dns_error rows is a reason to slow down, because neither status supports immediate suppression. Keep the generated mx-evidence.* directory with the CSV. Rows marked partial_mx retain a working direct route but need review of failed or incomplete target checks. The script makes DNS queries only and does not edit DNS or delete source rows.
Quick one-liner
  1. Best use: Fast discovery on a clean list of domains.
  2. Weak spot: Negative answers need status parsing before suppression.
Reviewable CSV
  1. Best use: Database cleanup where every domain needs one reasoned decision.
  2. Weak spot: Parked-domain patterns still need local policy and review.

Set the suppression policy first

The biggest mistake in bulk MX cleanup is deciding the removal rules after seeing a messy export. Set the policy first, run the script, then review the counts. That keeps the cleanup from turning into a guessing exercise where every strange result gets handled differently.
For most commercial lists, use four decision buckets. Suppress means the domain has a confirmed no-mail signal. Retry means DNS did not return a dependable answer. Review means the domain exists but its route is unusual or unusable. Keep means at least one normal mail route resolves before address-level validation. Suppression should exclude matching addresses from sending while retaining source rows and DNS evidence for later review.
  1. Suppress: NXDOMAIN, a valid null MX, and a repeatedly confirmed lack of any MX or implicit MX route.
  2. Retry: SERVFAIL, REFUSED, timeout, resolver disagreement, and incomplete target lookups.
  3. Review: Implicit MX, partial MX, unusable MX targets, CNAME targets, mixed null MX answers, and possible parked-domain patterns.
  4. Keep: At least one MX hostname that resolves directly to A or AAAA, with no applicable local suppression rule.
Do not treat a timeout as a bad domain on the first pass. Resolver rate limits, local network issues, and transient DNS failures can create false negatives. Run another pass for retry statuses at a slower rate and use another trusted resolver before suppressing anything.

Interpret provider-specific MX records

Google Admin console showing legacy Google Workspace MX records and priorities.
Google Admin console showing legacy Google Workspace MX records and priorities.
Provider intent matters. Google's current setup uses smtp.google.com with priority 1 as the single MX value for Google Workspace. Supported legacy values include ASPMX.L.GOOGLE.COM. Any account can use the new single value, but working legacy configurations do not require replacement. Compare a customer's result with the intended account configuration on the Google Workspace MX setup page before labelling older records as broken.
For a cold database, do not infer mailbox status from provider names alone. Hosted mail records publish a domain-level route; they do not confirm mailbox existence or SMTP availability. A possible parked-domain MX pattern needs review against current domain use and list context. The provider hostname alone does not establish that the domain is parked.
What MX cleanup cannot prove
  1. Mailbox exists: MX records publish a domain-level route; they do not confirm a working mail server or valid address.
  2. Catch-all status: DNS cannot confirm whether every local part is accepted.
  3. Consent: A working MX record says nothing about permission or engagement quality.
  4. Reputation: Recipient-domain health does not fix sender authentication or blocklist and blacklist issues.

Fix MX records for domains you manage

Cleaning a recipient list changes send eligibility. Repairing MX records changes DNS and requires control of the domain. For owned domains, check the authoritative nameservers (NS records) to locate the active DNS host, then compare the current MX set with the receiving provider's documented setup.
  1. Export the existing MX set and preference values before editing, and confirm which mail service should receive messages.
  2. Use the provider's fully qualified mail server hostnames (FQDNs), not raw IP addresses or CNAME targets. Verify their A or AAAA records.
  3. Remove obsolete routes only after confirming they are not intentional gateways or backup mail servers. Do not add a second MX record solely to increase the record count.
  4. Recheck authoritative DNS and recursive resolver answers after cache expiry, then test delivery to a mailbox you control. A successful DNS lookup alone does not verify receipt.
A single provider-approved MX record is valid. For example, Google Workspace MX setup documents one record at priority 1. Preserve deliberate redundancy where the provider requires it.

Where Suped fits after the bulk pass

The bulk MX pass is a data hygiene job. Suped is our DMARC reporting and email authentication platform. After recipient-list cleanup, teams can use Suped to review DMARC reports for owned domains, identify sending sources, and investigate SPF or DKIM failures. Those reports concern authentication on sent email, not the existence of recipient mailboxes.
After cleaning recipient domains, check the sending side before mailing the list. Suped's email tester helps inspect a real message, while DMARC monitoring and blocklist monitoring track issues that a one-time MX script cannot detect.
For agencies and MSPs, Suped's multi-tenant workflow keeps authentication monitoring and client reporting together for domains under management. Use the CSV results to manage recipient-list decisions separately.

Bulk MX cleanup checks and pitfalls

Best practices
Normalize domains before lookup so schemes, paths, ports, and spaces do not pollute results.
Classify null MX, NXDOMAIN, possible parked MX, and A/AAAA fallback before suppression.
Keep the raw DNS answer beside each decision so bad filters can be reversed later.
Sample a few suppressed domains manually before deleting records from a source database.
Common pitfalls
Treat no MX as review when an A or AAAA fallback exists, not as automatic deletion.
Do not merge SERVFAIL, REFUSED, or timeout results into a confirmed no-mail-route bucket.
Do not count an MX target as usable until it resolves directly to an A or AAAA record.
Do not suppress a domain solely because its MX hostname resembles a parked-domain route.
Expert tips
Resolve MX hostnames directly to address records and flag any CNAME target as malformed.
Deduplicate DNS lookups by domain, then map each result back to every original CSV row.
Track DNS response status, TTL, and attempt count so DNS failures remain fully reviewable.
Run sender-domain SPF, DKIM, DMARC, and MX checks before mailing the cleaned list at scale.

Frequency asked questions

Yes. A DNS MX lookup checks domain mail routing without connecting to recipient mail servers or sending messages.

No. If the domain has an A or AAAA record, SMTP uses an implicit MX route. Mark it for review and address-level validation.

A valid null MX is the domain's only MX record, with preference 0 and a single dot as its target. It tells senders that the domain accepts no mail.

Put them in a retry queue. Slow the lookup rate, retry later, and confirm persistent failures through another trusted resolver before changing the source list.

No. MX lookup identifies a published domain-level route. Even a target with a valid A or AAAA record does not confirm an accepting SMTP server, a working mailbox, or catch-all behavior. Consent and engagement need separate assessment.

Suped helps after recipient-list cleanup by monitoring owned-domain DMARC, SPF, DKIM, MTA-STS, blocklist or blacklist status, and authentication issues.
DMARC monitoring

Start monitoring your DMARC reports today

Suped DMARC platform dashboard
What you'll get with Suped
Real-time DMARC report monitoring and analysis
Automated alerts for authentication failures
Clear recommendations to improve email deliverability
Protection against phishing and domain spoofing