Sub topic 3
Proving who you are: SPF, DKIM, and DMARC
This chapter assumes you can read a DNS TXT record and know how an ESP or SMTP server sends mail on your behalf. You should also know the difference between transactional and marketing mail. The previous chapters covered the three possible outcomes (inbox, spam folder, rejection). This chapter covers the first thing a receiver checks: whether the message really comes from the domain it claims.
What authentication does and does not prove
Authentication ties a message to a sending identity, which is a domain. It does not say the sender is good. A spammer can pass SPF, DKIM, and DMARC on a domain they own. Authentication matters because reputation attaches to an identity, and the receiver can only build a history for that identity if it can trust the message really came from it. Without authentication, anyone could forge your domain and use up the reputation you built.
Each protocol answers a different question:
| Protocol | Question it answers | Identity it checks | Where the check data lives |
|---|---|---|---|
| SPF | Is this server allowed to send for this domain? | Envelope sender (MAIL FROM, shown as Return-Path) and the connecting IP | TXT record at the domain |
| DKIM | Was this message signed by this domain and left unaltered? | The `d=` domain in the signature | Public key in TXT at `selector._domainkey.domain` |
| DMARC | Does a passing check match the domain the user sees, and what should happen if not? | The visible From domain | TXT record at `_dmarc.domain` |
Message identities: why there are several "from" addresses
A message carries two sender addresses. The envelope sender is given during the SMTP conversation (MAIL FROM). It receives bounces and ends up in the Return-Path header. The header From is the address the recipient sees in their mail client.
SPF checks the envelope sender. DKIM checks whatever domain signed the message. Neither one, on its own, checks the header From. That gap would let an attacker pass SPF with their own envelope domain while showing your domain in the From line. DMARC closes the gap with alignment, described below.
SPF: authorizing sending servers
SPF (Sender Policy Framework) lets a domain list the servers allowed to use it as an envelope sender. The receiver takes the domain from MAIL FROM, looks up its SPF record, and checks whether the connecting IP address is in the list.
example.com. IN TXT "v=spf1 ip4:203.0.113.10 include:_spf.esp.example.net -all"Read it left to right:
v=spf1marks the record as SPF.ip4:203.0.113.10authorizes one IP address.include:_spf.esp.example.netpulls in the sending ranges your ESP publishes.-allsays every other source should fail.~allis a softer "soft fail".?allis neutral.
Common SPF errors:
- More than one SPF record. A domain must publish exactly one record starting with
v=spf1. Two records produce a permanent error. Merge them. - Too many DNS lookups. SPF evaluation may trigger at most 10 DNS-querying mechanisms (
include,a,mx,redirect, and similar). Chains ofinclude:from several vendors often exceed it, which returns apermerrorand fails the check. - Forwarding. When a message is forwarded, the forwarding server's IP is not in your record, so SPF fails at the final receiver. This is a built-in weakness of SPF and the reason DKIM matters.
- Checking the wrong domain. If your ESP uses its own bounce domain as the envelope sender, SPF passes for the ESP's domain, not yours. That pass will not align with your From domain.
DKIM: signing the message
DKIM (DomainKeys Identified Mail) uses a key pair. The sending system keeps the private key and adds a DKIM-Signature header. The domain publishes the public key in DNS under a selector. The selector is a label you choose, which lets you hold several keys at once and rotate them.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=selector1;
h=from:to:subject:date:message-id;
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=;
b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB...The tags that matter:
d=is the signing domain. This is the identity DKIM asserts.s=is the selector. The receiver queriesselector1._domainkey.example.comfor the public key.h=lists the signed headers. Always includeFrom.bh=is a hash of the body.b=is the signature over the headers and that hash.
If anything signed changes in transit (body text, a signed header), verification fails. Mailing lists that append footers or rewrite subjects often break signatures. Simple forwarding does not, which is why DKIM usually survives where SPF does not.
Common DKIM errors:
- Signing with the ESP's domain. If
d=is the ESP's domain, the signature is valid but does not align with your From domain. - Key published wrongly. Long keys are split into several quoted strings inside one TXT record because each string is limited to 255 characters. A missing quote or stray space breaks the key. Use 2048-bit RSA keys where your DNS provider allows it.
- Stale selectors. If you rotate keys, keep the old public key published until in-flight mail has been delivered.
DMARC: alignment and policy
DMARC (Domain-based Message Authentication, Reporting and Conformance) adds two things: a requirement that the authenticated domain match the visible From domain, and a published policy for failures.
A message passes DMARC when at least one of these holds:
- SPF passes and the envelope sender domain aligns with the From domain.
- DKIM passes and the
d=domain aligns with the From domain.
Alignment has two modes. In relaxed mode (the default), the two domains need only share the same organizational domain, so mail.example.com aligns with example.com. In strict mode they must match exactly.
A DMARC record sits at _dmarc.<domain>:
_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:[email protected]; adkim=r; aspf=r"| Tag | Meaning |
|---|---|
| `p` | Policy for the domain: `none`, `quarantine`, or `reject` |
| `sp` | Policy for subdomains, if different from `p` |
| `rua` | Address that receives aggregate (daily XML) reports |
| `adkim`, `aspf` | Alignment mode for DKIM and SPF: `r` relaxed, `s` strict |
| `pct` | Percentage of failing mail the policy applies to |
The reports in rua list every source that sent mail claiming your domain, with pass and fail counts. They are how you find a forgotten system, such as an invoicing tool, that sends as your domain without authentication.
Rolling it out in order
- Inventory every system that sends as your domain: the ESP, the CRM, the billing tool, and the helpdesk.
- Set up SPF with all legitimate sources, staying under 10 lookups.
- Configure DKIM for each sender, using your own domain as
d=. Most ESPs call this a custom or authenticated sending domain, and it usually means adding CNAME or TXT records they supply. - Publish DMARC at
p=nonewith aruaaddress and read the reports. - Fix failing sources, then tighten to
quarantine, optionally withpctbelow 100, then toreject.
Using a subdomain such as news.example.com for marketing mail keeps its reputation and its DMARC settings separate from your corporate mail.
Checking the result
Receivers record their verdicts in the Authentication-Results header. Read it on a test message delivered to a mailbox you control:
Authentication-Results: mx.receiver.example;
spf=pass smtp.mailfrom=bounce.example.com;
dkim=pass header.d=example.com header.s=selector1;
dmarc=pass header.from=example.comHere SPF passed for bounce.example.com, which aligns with example.com in relaxed mode. DKIM also passed with d=example.com. Either would be enough for DMARC.
Failure modes at a glance
| Symptom | Likely cause |
|---|---|
| `spf=permerror` | More than one SPF record, or more than 10 lookups |
| `spf=pass` but `dmarc=fail` | SPF passed for the ESP's bounce domain, which does not align with the From domain |
| `dkim=fail (body hash did not verify)` | Content changed after signing, often by a gateway or mailing list |
| `dkim=neutral (no key)` | Selector or DNS record missing or mistyped |
| DMARC passes in testing but fails for some mail | A second sender not yet included in SPF or not signing DKIM |
Exercise
A message has From: [email protected]. The receiver reports spf=pass smtp.mailfrom=bounce.esp.example.net and dkim=pass header.d=esp.example.net. Your DMARC record is p=reject with default alignment. What happens, and what is the fix?
Show answer
DMARC fails. SPF and DKIM both pass, but both for esp.example.net, which does not align with the From domain example.com, so p=reject causes the message to be refused. The fix is to configure the ESP to sign with your own domain (d=example.com, usually through DKIM records the ESP supplies) and, if possible, to use a custom bounce domain under example.com. Either aligned pass is enough. In future, stay at p=none until reports show every sender is aligned.
Exercise
Why does DKIM usually survive forwarding when SPF does not?
Show answer
SPF checks the IP address of the server that delivers the message to the final receiver. A forwarder's IP is not in the original domain's SPF record, so the check fails. DKIM signs the message content and headers, and a plain forward leaves those unchanged, so the signature still verifies against the public key in the signing domain's DNS.