Blog
SPF, DKIM and DMARC for developers, with real record examples
SPF, DKIM and DMARC explained for developers: real DNS records, how receivers evaluate them, alignment, the 2024 Google and Yahoo rules, and common fixes.
Updated 2026-11-23
SPF, DKIM and DMARC are DNS records that let receivers check whether a message really comes from the domain it claims. SPF (RFC 7208) lists the servers allowed to send for a domain, DKIM (RFC 6376) publishes the key that verifies a signature on each message, and DMARC (RFC 7489) requires one of the two to pass for the domain in the visible From header and tells receivers what to do when neither does. Since February 2024, Google and Yahoo require all three from bulk senders.
Three records, three questions
| Record | Standard | Question it answers | Where it lives | Starts with |
|---|---|---|---|---|
| SPF | RFC 7208 | Which servers may send mail for this domain? | TXT at the domain itself | v=spf1 |
| DKIM | RFC 6376 | Was this message signed by the domain, and is it unchanged? | TXT at selector._domainkey.domain |
v=DKIM1 (optional) |
| DMARC | RFC 7489 | What should a receiver do when a message fails, and where do reports go? | TXT at _dmarc.domain |
v=DMARC1 |
The three cover each other's gaps. SPF checks a domain the reader never sees. DKIM proves a signature but says nothing about which domain should have signed. DMARC ties both to the From address and adds a policy.
A complete set of records for one domain
Take a company that uses Google Workspace for its mailboxes, an app server at 192.0.2.10 for invoices, and a newsletter platform that sends from a subdomain. Its records look like this:
example.com. TXT "v=spf1 include:_spf.google.com ip4:192.0.2.10 -all"
google._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
_dmarc.example.com. TXT "v=DMARC1; p=quarantine; sp=reject; rua=mailto:dmarc-reports@example.com"
news.example.com. TXT "v=spf1 include:spf.sender.example -all"
s1._domainkey.news.example.com. CNAME s1.dkim.sender.example.
_spf.google.com is the include Google documents for Workspace, and google is Workspace's default DKIM selector. The newsletter platform, sender.example, is a stand-in: use the include and the CNAME its setup page gives you. The key is shortened.
A domain that never sends mail needs records too, or anyone can send as it:
example.net. MX 0 .
example.net. TXT "v=spf1 -all"
_dmarc.example.net. TXT "v=DMARC1; p=reject"
The null MX (RFC 7505) says the domain accepts no mail, -all says no server may send for it, and p=reject asks receivers to refuse anything that claims otherwise.
To read any domain's records from a terminal:
dig +short TXT example.com
dig +short TXT _dmarc.example.com
dig +short TXT google._domainkey.example.com
SPF in detail
A receiver evaluates SPF for the domain of the envelope sender, the address in the SMTP MAIL FROM command, also called the Return-Path. Receivers may also check the HELO name. SPF does not look at the From header people see. It reads the record left to right and stops at the first term that matches the connecting IP address.
| Term | Matches when | DNS lookups |
|---|---|---|
ip4:192.0.2.0/24, ip6:2001:db8::/32 |
The sending address is in the range | 0 |
a, mx |
The sending address is an address of the domain, or of one of its MX hosts | 1 each |
include:_spf.google.com |
The included domain's own SPF evaluation returns pass | 1, plus everything inside it |
exists:, ptr, redirect= |
Rarely needed; RFC 7208 says not to publish ptr |
1 each |
-all / ~all |
Always: fail or softfail whatever is left | 0 |
The qualifier of the matching term gives the result: + (the default) gives pass, - gives fail, ~ gives softfail and ? gives neutral. RFC 7208 section 2.6 defines three more results: none when there is no record, temperror for a DNS failure, and permerror for a broken record.
Three rules break more records than any typo:
- One record per domain. Two
v=spf1records make every evaluation end inpermerror(RFC 7208 section 4.5). Merge them. - At most 10 DNS lookups across the whole include tree, and at most 2 void lookups that return nothing (section 4.6.4). Past either limit,
permerror. - An include is not a paste. It runs the other domain's evaluation and matches only if that evaluation passes. A
-allinside an included record does not make yours fail.
DKIM in detail
The sending server signs selected headers and the body with a private key, and adds a DKIM-Signature header:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=google;
h=from:to:subject:date:message-id; bh=...; b=...
d= is the signing domain and s= the selector. Together they give the location of the public key: google._domainkey.example.com. The receiver fetches it, recomputes the hashes, and checks the signature. bh= is the body hash, so a footer added in transit breaks it.
What to get right:
- Key length. RFC 8301 requires RSA keys of at least 1024 bits and recommends 2048, and forbids
rsa-sha1for signing and verifying. RFC 8463 adds Ed25519 keys; use one only next to an RSA signature, since not every verifier supports it. - Selectors. Each sending service signs with its own selector, and DNS cannot list them. Keep an inventory.
- Rotation. Publish a new key under a new selector, switch signing to it, wait until mail signed with the old key has been delivered, then revoke the old one with an empty
p=. - Testing mode.
t=yin the key record asks verifiers not to treat your mail differently from unsigned mail. Remove it once signing works.
DMARC in detail
DMARC passes when SPF or DKIM passes for a domain aligned with the From header. Alignment is the key idea:
From: news@example.com, domain that passed |
Relaxed (r, default) |
Strict (s) |
|---|---|---|
example.com |
Aligned | Aligned |
news.example.com |
Aligned: same organizational domain | Not aligned |
sender.example, the platform's own domain |
Not aligned | Not aligned |
The third row is the classic failure. A platform sends with its own Return-Path and signs with its own d=: SPF passes, DKIM passes, and DMARC still fails, because neither pass is for your domain. The fix is custom DKIM signing with your domain in the platform's settings.
The tags that matter:
| Tag | Meaning | Default |
|---|---|---|
p= |
Policy for failing mail: none, quarantine or reject |
Required |
sp= |
Policy for subdomains | Same as p |
rua= |
Where aggregate reports go, as mailto: URIs |
None |
pct= |
Share of failing mail the policy applies to | 100 |
adkim=, aspf= |
Alignment mode for DKIM and SPF | r |
A policy is a request. RFC 7489 leaves the final decision to the receiver's local policy.
Roll out without losing mail
- Publish
p=nonewith arua=address you read. Nothing changes for delivery; reports start arriving, one XML file per receiver, usually daily. - List every source in the reports that sends as your domain. Decide which are yours.
- Make each legitimate source pass with alignment, preferably with DKIM signing under your domain.
- Set
sp=rejectearly if your subdomains send nothing. - Move to
p=quarantine, thenp=rejectonce the reports show no legitimate source failing.
A report address on another organizational domain only works if that domain agrees: receivers look for a TXT record such as example.com._report._dmarc.reports.example.net containing v=DMARC1.
Forwarding and mailing lists
Forwarding breaks SPF: the forwarding server connects with its own IP address, which is not in your record. DKIM survives as long as the message is not changed. Mailing lists often change it, adding a subject tag or a footer, which breaks the body hash. ARC, the Authenticated Received Chain of RFC 8617, lets intermediaries record the results they saw before changing the message, and receivers may take that into account. On your side, the practical rule is to sign every message with DKIM for your own domain, so at least one aligned check has a chance to survive the trip.
What Google and Yahoo require since February 2024
Google's email sender guidelines and Yahoo's sender requirements took effect in February 2024. Google's version:
| Requirement | All senders to Gmail | Bulk senders (more than 5,000 messages a day to personal Gmail accounts) |
|---|---|---|
| SPF or DKIM | Yes | SPF and DKIM, both |
| DMARC record | Not required | Required, p=none at least |
| From domain aligned with SPF or DKIM domain | Not required | Required |
| Valid forward and reverse DNS for sending IPs | Yes | Yes |
| TLS for transmitting mail | Yes | Yes |
| Spam rate in Postmaster Tools | Below 0.3% | Below 0.3% |
| One-click unsubscribe (RFC 8058) on marketing mail | Not required | Required, honored within 2 days |
Yahoo announced matching rules for bulk senders at the same time. Both providers publish their current versions, which you should read before a large send: the thresholds are theirs to change.
Check the domain of any address with the API
When you verify an email address, the result tells you whether its domain publishes SPF and DMARC. These fields are computed before the mailbox check, so fast mode returns them too:
curl https://api.qelka.com/v1/email \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"email": "jane@example.com", "mode": "fast"}'
The result carries "domain": { "name": "example.com", "spf": true, "dmarc": true }. In JavaScript, for example to warn a customer who sends mail through you from their own domain:
export async function domainAuthentication(email) {
const response = await fetch('https://api.qelka.com/v1/email', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, mode: 'fast' }),
signal: AbortSignal.timeout(5000),
})
if (!response.ok) return null
const { domain } = await response.json()
const missing = []
if (domain.spf === false) missing.push('SPF')
if (domain.dmarc === false) missing.push('DMARC')
return { domain: domain.name, missing }
}
domain.spf is true when the domain publishes an SPF record, domain.dmarc when the domain or its organizational domain publishes a DMARC record. Both are null when they were not checked, for example after a syntax failure. They are presence checks: a published record can still be broken, which the free SPF checker and DMARC checker show in detail. The API does not report DKIM, because a selector only appears in a signed message. Each call costs 1 credit.
What to do with what you find
| Finding | Where | What to do |
|---|---|---|
| Two SPF records | Your domain | Merge them into one |
| SPF over 10 lookups | Your domain | Remove unused includes; use ip4 and ip6 where addresses are stable |
SPF ends in +all or ?all |
Your domain | End in -all, or ~all while you finish the inventory of senders |
DMARC with no rua= |
Your domain | Add a report address you read |
DMARC stuck at p=none |
Your domain | Read the reports, fix failing senders, move to quarantine then reject |
| DKIM key of 1024 bits | Your domain | Publish a 2048-bit key under a new selector and switch to it |
| Platform mail fails DMARC | Your domain | Turn on custom DKIM signing with your domain in the platform |
domain.spf: false on a signup |
An address you checked | Nothing: the domain can still receive mail |
domain.spf and domain.dmarc both false on a customer domain you send for |
An address you checked | Tell the customer before their deliverability suffers |
Do not reject a signup because its domain lacks SPF or DMARC. Those records protect a domain's outgoing mail; a domain without them receives mail perfectly well.
Where to go next
The free DKIM checker reads a key for a selector you give it, and the DNS lookup shows any raw record. SPF, DKIM and DMARC explained covers the domain fields of an email result in more depth. When bounces are the problem rather than authentication, read email bounces and list hygiene, and How to verify an email address explains every other check in the same call.
Frequently asked questions
What is the difference between SPF, DKIM and DMARC?
Do I need SPF, DKIM and DMARC?
What is DMARC alignment?
Why does SPF fail when an email is forwarded?
What happens if my SPF record has more than 10 DNS lookups?
Which DMARC policy should I start with?
How do I find my DKIM selector?
Put this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.