How to check SPF, DKIM and DMARC for a list of domains

Three public DNS records decide whether a stranger can send email that looks like it comes from a domain. Anyone can read them, for any domain, with dig (macOS and Linux) or nslookup (Windows). This page shows how to read each one, what the common mistakes look like, and how to run the same check over a list.

1. SPF: who may send

dig +short TXT example.com | grep -i "v=spf1"

SPF is one TXT record on the domain itself that lists the servers allowed to send its mail. The last word says what to do with everyone else:

EndingMeaning
-allReject senders that are not listed. The strict setting.
~allAccept them but mark them as suspicious (soft fail). Common, and fine together with DMARC.
?allNo opinion. Protects nothing.
+allEveryone may send. A mistake.

Three things break SPF without anyone noticing:

2. DMARC: what to do when the checks fail

dig +short TXT _dmarc.example.com

DMARC lives on the _dmarc name. The parts that matter:

TagMeaning
p=noneOnly report. Forged mail is still delivered.
p=quarantineSend failing mail to spam.
p=rejectRefuse failing mail.
pct=The share of mail the policy applies to. Missing means 100.
rua=Where daily reports go. Without it nobody sees who is sending as the domain.
sp=A separate policy for subdomains.

A subdomain without its own record uses the record of the main domain, so check _dmarc.example.com when _dmarc.mail.example.com is empty.

3. DKIM: the signing keys

dig +short TXT selector1._domainkey.example.com

DKIM keys sit under a name chosen by the sender, called the selector, so you cannot list them: you have to know or guess the name. Open any email from the domain, view its source and find s= in the DKIM-Signature header. Common selectors are google (Google Workspace), selector1 and selector2 (Microsoft 365), k1 (Mailchimp) and s1, s2 (SendGrid).

In the record, p= holds the public key. An empty p= means the key was withdrawn, and t=y means the domain is only testing.

4. MX: does the domain receive mail at all

dig +short MX example.com

The answer lists the mail servers, lowest number first. A single line 0 . means the domain declares that it accepts no mail.

On Windows

nslookup -type=TXT example.com
nslookup -type=TXT _dmarc.example.com
nslookup -type=MX example.com

A list of domains

Put one domain per line in domains.txt:

while read -r d; do
  echo "== $d"
  dig +short TXT "$d" | grep -i "v=spf1" || echo "no SPF record"
  dig +short TXT "_dmarc.$d" | grep -i "v=DMARC1" || echo "no DMARC record"
  dig +short MX "$d" | head -n 3
done < domains.txt

This prints the raw records. It does not count SPF lookups through the includes, does not look for DKIM keys, and does not fall back to the main domain's DMARC record for subdomains. For a few dozen domains, reading the output by hand is quick enough.

For a long list

Our Email Security Checker on Apify runs these checks for every domain in a list and returns a table: the records, the SPF lookup count including includes, DKIM keys found under 47 common selector names, the policy that applies, and what is wrong in plain words. It reads public DNS only. It costs $0.005 a domain, paid by card through Apify, with no subscription.