Sub topic 3
Proving who you are: SPF, DKIM, and DMARC
This chapter assumes you know how to add TXT records in DNS, understand the basic path of an email from sender to recipient, and can tell transactional mail from marketing mail. Authentication is the first check a receiving provider runs. It ties a message to a domain, and later chapters build reputation on that tie.
What authentication proves
Email's original protocol lets anyone write any address in the visible From header. Authentication adds three checks:
- SPF (Sender Policy Framework) proves that the server connecting to the receiver is allowed to send for a domain.
- DKIM (DomainKeys Identified Mail) proves that a domain signed the message and that the signed parts were not changed in transit.
- DMARC (Domain-based Message Authentication, Reporting and Conformance) requires that SPF or DKIM passes for a domain that matches the visible From domain. It also tells receivers what to do when neither does.
None of these proves a message is wanted. They prove identity, and identity is what reputation attaches to.
The three records
; SPF: which servers may send for example.com
example.com. IN TXT "v=spf1 include:_spf.esp.example.net -all"
; DKIM: public key published under a selector chosen by the sender
selector1._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...(public key truncated)..."
; DMARC: policy and aggregate report address, starting in monitoring mode
_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:[email protected]"The hostnames and key are placeholders. Your email service provider (ESP) gives you the real values.
SPF
SPF checks the envelope sender (the Return-Path address used in the SMTP conversation) and the connecting IP address. The receiver looks up the TXT record for the envelope domain and checks whether the IP is listed. In the example, include: pulls in the ESP's list of servers, and -all means every other server fails.
Two limits cause common errors. A record may trigger at most 10 DNS lookups (include, a, mx and similar mechanisms count), and exceeding that gives a permanent error. A domain should also publish only one SPF record. Two records invalidate each other.
SPF breaks when mail is forwarded, because the forwarder's IP is not in the original domain's record.
DKIM
The sending server signs selected headers and the body with a private key. It adds a DKIM-Signature header that names the signing domain (d=) and the selector (s=). The receiver looks up selector._domainkey.domain, fetches the public key, and verifies the signature. Selectors let you run several keys at once and rotate them without downtime.
DKIM usually survives forwarding. It fails if a system changes the signed content, for example by adding a footer after signing.
DMARC
DMARC adds alignment. The domain that passed SPF or DKIM must match the domain in the visible From header. A message can pass SPF for bounce.esp.example.net and still fail DMARC if the From domain is example.com. DMARC passes when at least one of the two checks passes and aligns.
The p= tag sets the policy: none (monitor only), quarantine (treat as suspicious), or reject (refuse). The rua= tag names where receivers send daily aggregate reports.
Rolling out safely
- Publish SPF and DKIM for every system that sends as your domain, including your ESP, your CRM, and your ticketing tool.
- Publish DMARC with
p=noneand aruaaddress. - Read the aggregate reports for a few weeks and fix any legitimate sender that fails.
- Move to
quarantine, then toreject, once legitimate mail passes consistently.
<br>
Common errors
| Symptom | Likely cause |
|---|---|
| SPF `permerror` | More than 10 lookups, or two SPF records |
| DKIM `fail` (body hash) | Content changed after signing |
| DMARC fail with SPF pass | Envelope domain does not align with From domain |
| DKIM `none` | Selector record missing or misspelled |
Exercise
A message passes SPF for bounce.esp.example.net and carries no DKIM signature. The From address is [email protected]. Does it pass DMARC, and what is the fix?
Show answer
It fails DMARC. SPF passed, but for a domain that does not align with example.com, and there is no DKIM signature to provide a second path. The fix is to enable DKIM signing with d=example.com (or configure a custom return-path domain under example.com so SPF aligns).