Helenis API
Start for free

Web data & toolsEmail Security

SPF, DKIM and DMARC Checker API: Grade Any Domain's Email Security

SPF, DKIM and DMARC checker API guide: grade a domain's email security A to F, count SPF lookups, read DNS records and watch SSL expiry, with Python.

SPF, DKIM and DMARC Checker API cover: a file cabinet sticker, an arrow and a JSON response grading github.com C with a score of 65, Microsoft 365 as mail provider and 10 SPF lookups.
Even github.com gets a C: 10 SPF lookups out of the 10 allowed, and no MTA-STS.

Since February 2024, Gmail and Yahoo require bulk senders (for Gmail, more than 5,000 messages a day to its users) to publish SPF, sign with DKIM and have a DMARC record. Microsoft applied the same rule to Outlook.com in May 2025. A domain that misses one sees its mail rejected or sent to spam, which is why an SPF, DKIM and DMARC checker API now sits in so many onboarding flows.

Checking a domain by hand means three or four dig commands, a recursive count of SPF includes, and guesses at DKIM selectors. For one domain that is ten minutes; for an agency onboarding 40 clients, or a sending platform validating every new customer domain, it has to be code that does the lookups, applies the rules the receiving servers apply, and says what to fix.

This tutorial explains what each record proves and where domains usually fail, then audits real domains in Python with the DNS Lookup, Email Security & SSL Checker API: an email grade, DNS records and SSL certificates.

What SPF, DKIM and DMARC each prove

Record Where it lives What it proves Standard
SPF TXT on the domain Which servers may send mail for it RFC 7208
DKIM TXT at <selector>._domainkey.<domain> The message was signed by the domain and not altered RFC 6376
DMARC TXT at _dmarc.<domain> What receivers should do when SPF and DKIM do not align with the From domain, and where to send reports RFC 7489
MTA-STS TXT at _mta-sts plus a policy file over HTTPS Mail to the domain must travel over verified TLS RFC 8461
BIMI TXT at default._bimi The brand logo to show in supporting inboxes; needs DMARC at quarantine or reject BIMI Group draft

The failures are predictable:

  • SPF over 10 lookups. Each include, a, mx, ptr, exists and redirect costs a DNS lookup, nested includes count too, and RFC 7208 caps the total at 10. Past that, receivers return permerror and SPF fails for every message. Marketing tools are added one include at a time until someone crosses the line.
  • DMARC that only watches. p=none collects reports but delivers spoofed mail. It satisfies the Gmail and Yahoo minimum and protects nobody.
  • DKIM nobody can see. There is no way to list a domain's selectors from DNS. A checker has to try names (google for Google Workspace, selector1 and selector2 for Microsoft 365, k1 for Mailchimp, s1 and s2 for SendGrid) and admit when it found nothing.

Checking by hand versus an API

Step By hand With the API
SPF record dig TXT domain Parsed, all qualifier extracted
SPF lookup count Follow every include recursively lookups, warning from 9
DMARC dig TXT _dmarc.domain, read the tags policy, subdomain_policy, pct, rua
DKIM Guess selectors one dig at a time 20 common selectors in parallel, wildcard records ignored
MTA-STS, BIMI Two more lookups and an HTTPS fetch One status each
Verdict Your judgment Grade A-F, score 0-100, recommendations

Audit a domain's email security in Python

GET /v1/dns/email?domain= runs the whole audit for 1 credit. The input can be a domain, a host name or a URL.

Python
import requests

HOST = "dns-lookup-email-security-ssl-checker.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}

r = requests.get(
    f"{API}/v1/dns/email", headers=HEADERS, params={"domain": "github.com"}, timeout=30
)
r.raise_for_status()
audit = r.json()
print(audit["grade"], audit["score"], audit.get("provider"))
for fix in audit["recommendations"]:
    print("-", fix)

The real response for github.com, in 2.0 seconds (only the SPF record is shortened):

JSON
{
  "domain": "github.com",
  "grade": "C",
  "score": 65,
  "mx": [{ "value": "github-com.mail.protection.outlook.com", "ttl": 262, "priority": 0 }],
  "provider": "Microsoft 365",
  "mx_check": { "status": "pass", "message": "1 mail server(s)." },
  "spf": {
    "record": "v=spf1 ip4:192.30.252.0/22 ... include:spf.protection.outlook.com include:_netblocks.google.com ... include:sendgrid.net ... ~all",
    "all": "~all",
    "includes": ["spf.protection.outlook.com", "_netblocks.google.com", "_netblocks2.google.com", "mail.zendesk.com", "_spf.salesforce.com", "servers.mcsv.net", "mktomail.com", "sendgrid.net"],
    "lookups": 10,
    "check": { "status": "warn", "message": "10 DNS lookups out of 10: one more sender breaks SPF." }
  },
  "dmarc": {
    "record": "v=DMARC1; p=quarantine; sp=reject; pct=100; rua=mailto:dmarc@github.com; ruf=mailto:dmarc@github.com; fo=1",
    "policy": "quarantine",
    "subdomain_policy": "reject",
    "pct": 100,
    "rua": ["mailto:dmarc@github.com"],
    "check": { "status": "pass", "message": "DMARC quarantines spoofed mail (p=quarantine)." }
  },
  "dkim": {
    "selectors_found": ["google", "selector1", "k1", "k2", "s1", "s2", "cm"],
    "check": { "status": "pass", "message": "DKIM key found (google, selector1, k1, k2, s1, s2, cm)." }
  },
  "mta_sts": { "status": "warn", "message": "No MTA-STS: mail to this domain can be downgraded to plain text." },
  "bimi": { "status": "warn", "message": "No BIMI logo." },
  "recommendations": [
    "Bring SPF below 10 DNS lookups: remove senders you no longer use or replace includes with their IP ranges.",
    "Enable MTA-STS to enforce encrypted delivery."
  ]
}

GitHub authorises seven sending services (Microsoft 365, Google, Zendesk, Salesforce, Mailchimp, Marketo, SendGrid) through eight includes, and with their nested includes they add up to exactly 10 lookups. The record is still valid, but the next tool added to it will break SPF for all of GitHub's mail. The DKIM selectors tell the same story from the other side: one key per sending service.

The grade is a weighted score: SPF up to 30 points, DMARC 35, DKIM 20, MTA-STS 10, BIMI 5. A is 85 or more, B 70, C 50, D 30, F below.

The same call with curl:

Terminal
curl "https://dns-lookup-email-security-ssl-checker.p.rapidapi.com/v1/dns/email?domain=github.com" \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -H "X-RapidAPI-Host: dns-lookup-email-security-ssl-checker.p.rapidapi.com"

Email security grades of four well-known domains

Four real audits, made the same day:

Domain Grade Score Provider SPF lookups DMARC policy DKIM selectors found Missing
mozilla.org A 90 Google Workspace 7 reject google MTA-STS
stripe.com A 85 Google Workspace 7 reject google, s1, s2, mandrill, cm MTA-STS, BIMI
github.com C 65 Microsoft 365 10 quarantine 7 selectors MTA-STS, BIMI; SPF at the limit
python.org C 65 not detected (mail.python.org) 8 none google, k2 MTA-STS, BIMI; DMARC enforcement

Mozilla is the only one with a BIMI record, which it can publish because its DMARC policy is reject. Python.org loses its points on DMARC:

JSON
{
  "dmarc": {
    "record": "v=DMARC1; p=none; pct=100; rua=mailto:re+shb8ybr70a3@dmarc.postmarkapp.com; sp=none; aspf=r;",
    "policy": "none",
    "subdomain_policy": "none",
    "pct": 100,
    "rua": ["mailto:re+shb8ybr70a3@dmarc.postmarkapp.com"],
    "check": { "status": "warn", "message": "DMARC only monitors (p=none): spoofed mail is delivered." }
  },
  "recommendations": [
    "Move DMARC from p=none to p=quarantine, then p=reject, once the aggregate reports show your senders pass SPF or DKIM.",
    "Enable MTA-STS to enforce encrypted delivery."
  ]
}

The reports go to a DMARC monitoring service, the usual first step. The second step, which many domains never take, is to read those reports, fix the senders that fail alignment, and move to p=quarantine, then p=reject, as the recommendation says.

A domain that sends and receives no mail is graded on what it declares, not on what it lacks. example.com publishes a null MX (RFC 7505), v=spf1 -all and p=reject, and gets an A at 95: its MX check reads "Null MX (RFC 7505): this domain declares it accepts no mail.", and DKIM and MTA-STS pass with "No DKIM needed: the domain sends no mail (v=spf1 -all)." and "No MTA-STS needed: the domain accepts no mail." Parked domains deserve the same three records, since spammers like to forge domains that publish nothing.

Mozilla's SPF also shows why lookups must be counted, not includes: include:%{i}._ip.%{h}._ehlo.%{d}._spf.vali.email is an SPF macro that a receiver expands per message, and it still costs one lookup.

Get DNS records with TTL and priority

GET /v1/dns/records returns the records a public resolver sees: A, AAAA, CNAME, MX, NS, TXT, SOA and CAA by default, SRV and PTR on request, 1 credit per call.

Python
r = requests.get(
    f"{API}/v1/dns/records",
    headers=HEADERS,
    params={"domain": "python.org", "types": "A,AAAA,MX,TXT,CAA"},
    timeout=30,
)
r.raise_for_status()
records = r.json()["records"]
verifications = [t["value"] for t in records["TXT"] if "verification" in t["value"]]
print(len(verifications), "verification tokens; CAA:", records["CAA"])

The response, trimmed (two of the four A records, no AAAA, four of the 13 TXT records):

JSON
{
  "domain": "python.org",
  "records": {
    "A": [
      { "value": "151.101.128.223", "ttl": 17 },
      { "value": "151.101.0.223", "ttl": 17 }
    ],
    "MX": [{ "value": "mail.python.org", "ttl": 60, "priority": 50 }],
    "TXT": [
      { "value": "MS=73147F1EC0843C399CF17F586EC6B8EAF8C57961", "ttl": 300 },
      { "value": "v=spf1 mx ip4:188.166.95.178/32 ip6:2a03:b0c0:2:d0::71:1 include:stspg-customer.com include:_spf.google.com include:mailgun.org ~all", "ttl": 300 },
      { "value": "twilio-domain-verification=1c295667813cc0aaae819ed7657818f8", "ttl": 300 },
      { "value": "status-page-domain-verification=9y2klhzbxsgk", "ttl": 300 }
    ],
    "CAA": []
  }
}

Two things stand out. The TXT verification tokens list the SaaS products the organisation has connected to its domain, a cheap signal that the tech stack lookup article explores further. And CAA is empty: any certificate authority may issue certificates for python.org. A CAA record (RFC 8659) restricts issuance to the authorities you actually use.

SSL certificate checker: expiry and the reason it fails

GET /v1/dns/ssl opens a TLS connection on port 443 and reports the certificate. When validation fails, it connects a second time without validation to read the certificate and tell you why. For a deliberately expired test host:

JSON
{
  "domain": "expired.badssl.com",
  "host": "expired.badssl.com:443",
  "valid": false,
  "error": "certificate has expired",
  "subject": "*.badssl.com",
  "issuer": "COMODO RSA Domain Validation Secure Server CA",
  "issuer_organization": "COMODO CA Limited",
  "names": ["*.badssl.com", "badssl.com"],
  "valid_from": "2015-04-09T00:00:00Z",
  "valid_until": "2015-04-12T23:59:59Z",
  "days_remaining": -4247,
  "key": "RSA 2048",
  "protocol": "TLSv1.2",
  "cipher": "ECDHE-RSA-AES128-GCM-SHA256"
}

wrong.host.badssl.com returns valid: false with "error": "Hostname mismatch, certificate is not valid for 'wrong.host.badssl.com'.", and www.python.org returns valid: true, a GlobalSign certificate covering www.python.org, *.python.org and python.org, served over TLS 1.3.

Certificates are getting shorter: the CA/Browser Forum voted in 2025 to bring the maximum lifetime down in steps to 47 days by 2029. Renewal is automated for most sites, and automation fails silently. A daily check is cheap:

Python
HOSTS = ["www.python.org", "api.example-shop.com", "status.example-shop.com"]

for host in HOSTS:
    r = requests.get(
        f"{API}/v1/dns/ssl", headers=HEADERS, params={"domain": host}, timeout=30
    )
    cert = r.json()
    if r.status_code == 400:
        print(f"{host}: {cert['error']['code']}")  # site_unreachable: not billed
    elif not cert["valid"]:
        print(f"{host}: INVALID, {cert['error']}")
    elif cert["days_remaining"] < 21:
        print(f"{host}: renew, {cert['days_remaining']} days left")

Audit a list of client domains to CSV

Agencies, managed service providers and deliverability teams run the same audit across every domain they look after. One row per domain, with the fields that drive the conversation; 503 dns_timeout is retried and never billed:

Python
import csv
import time

import requests

HOST = "dns-lookup-email-security-ssl-checker.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
DOMAINS = ["github.com", "stripe.com", "mozilla.org", "python.org"]


def email_audit(domain: str, attempts: int = 3) -> dict:
    for attempt in range(attempts):
        r = requests.get(
            f"{API}/v1/dns/email",
            headers=HEADERS,
            params={"domain": domain},
            timeout=30,
        )
        if r.status_code != 503:
            break
        time.sleep(2 * 2**attempt)
    return r.json()


with open("email_audit.csv", "w", newline="", encoding="utf-8") as out:
    writer = csv.writer(out)
    writer.writerow(
        ["domain", "grade", "score", "provider", "spf_lookups", "dmarc", "fixes"]
    )
    for domain in DOMAINS:
        a = email_audit(domain)
        if "error" in a:
            writer.writerow([domain, "", "", "", "", "", a["error"]["code"]])
            continue
        writer.writerow(
            [
                domain,
                a["grade"],
                a["score"],
                a.get("provider", ""),
                a["spf"].get("lookups", ""),
                a["dmarc"].get("policy", "missing"),
                " | ".join(a["recommendations"]),
            ]
        )

Sorted by score, the CSV is a work plan: domains without DMARC first, then p=none, then SPF near the limit. The same loop gives sales teams a talking point; a prospect whose DMARC is missing has a spoofing problem you can show them.

Pricing and the Apify actor

Every endpoint costs 1 credit per call. The free BASIC plan gives 10 calls a day. PRO is $3.99 a month for 50,000 calls, about $0.00008 each; ULTRA is $9.99 for 250,000 and MEGA $29.99 for 1,000,000. Invalid domains and DNS timeouts use no credits. Plans are on the DNS and email security page, parameters in the API reference.

The DNS Lookup, Email Security & SSL Checker actor on Apify runs the same checks over a list of domains and exports a table, at $0.0012 per email audit and $0.0005 per SSL check or DNS lookup. To check whether a domain name is still free before any of this, see the domain availability API tutorial; for the security headers of the website itself, the security headers checker.

What the SPF, DKIM and DMARC checker does not do

  • No test message. It reads DNS; it does not send mail, so it cannot see whether your real messages pass alignment or land in spam. Send a test to a mailbox you control for that.
  • DKIM on 20 common selectors. A custom selector is not found, and the check says so ("it may use a custom one") instead of declaring DKIM missing.
  • No DMARC report parsing. The rua addresses are listed; the aggregate XML reports they receive are not read.
  • No blocklist lookups. IP and domain reputation on DNSBLs is not checked.
  • SSL on port 443 only, without revocation (OCSP) or a list of accepted cipher suites; the website security audit tests TLS versions.
  • The grade is our scale. It is documented and stable, but it is not an industry standard; compare the checks, not only the letter.

Frequently asked questions

How do I check the SPF, DKIM and DMARC records of a domain?

SPF is a TXT record on the domain starting with v=spf1; DMARC is a TXT record at _dmarc.<domain>; DKIM keys sit at <selector>._domainkey.<domain>, so you need the selector name. dig or nslookup reads them one by one; GET /v1/dns/email reads and grades all of them in one call.

What does SPF "permerror: too many DNS lookups" mean?

The SPF record needs more than 10 DNS lookups to evaluate once every include is expanded, so receivers stop and treat SPF as failed. Remove services you no longer use, replace includes with the IP ranges they stand for, or move some senders to a subdomain with its own SPF record.

Is DMARC p=none enough for Gmail and Yahoo?

For bulk senders, the published minimum is a DMARC record, and p=none satisfies it. It does not stop anyone from spoofing your domain. Use the reports to fix legitimate senders, then move to quarantine and reject.

How can I find a domain's DKIM selector?

DNS has no way to list selectors. Look at the DKIM-Signature header of a message the domain sent: the s= tag is the selector. Without a message, try the names the big providers use, which is what the API does with 20 common selectors.

Why does a big company get a C?

Because the grade measures DNS records, not the security team. Large organisations often have many sending services (hence SPF near 10 lookups) and rarely publish MTA-STS or BIMI. A C usually means one or two precise fixes.

Get started

DNS Lookup API

DNS records, email security audit (SPF, DMARC, DKIM) with a grade, and SSL certificate expiry.

  • Email Security
  • DMARC
  • DNS
  • Python
  • Email Deliverability