Networking / SPF, DKIM and DMARC

SPF, DKIM and DMARC

Email lets anyone type any From address. Three DNS records give a receiving server the means to check the claim: a list of allowed servers, a signature, and a policy that ties both to the visible sender.

Intermediate7 steps~7 min
Sender — the real mail server of example.com
Forger — pretends to write from example.com
Receiver — the mail server that runs the checks
DNS — public records only the owner can edit
// THE SHORT VERSION

In 30 seconds

Email itself never checks who wrote the From line. A domain owner fixes that by publishing three records in DNS.

SPF lists the servers allowed to send mail for the domain. DKIM publishes a key so receivers can verify a signature that the real server adds to every message.

DMARC ties them to the address people see: at least one of the two checks must pass for the same domain as the From line. It also tells receivers whether to deliver, quarantine or reject mail that fails, which is what stops a forger using the domain.

SPF, DKIM and DMARC, step by step

STEPS01 / 07

Simplified: alignment can be relaxed (subdomains count) or strict, and forwarding can break SPF. DMARC protects the exact domain only; a look-alike domain can publish valid records of its own.

STEP 01 / 07 Anyone can write any From
THE MATH
From: billing@example.com really sent by: 203.0.113.66 SMTP checks neither
  1. Step 1: Anyone can write any From. Email was designed without proof of origin. The From line is plain text that the sending computer fills in, like the return address on a paper envelope. A forger at 203.0.113.66 can write billing@example.com there, and to the receiving server the result looks the same as real mail from example.com.
  2. Step 2: Three records in DNS. The fix is for the owner of example.com to publish instructions where only the owner can: in the domain’s DNS. Three text records do it. SPF lists the servers allowed to send, DKIM holds a public key for checking signatures, and DMARC says what to do with mail that fails. Any receiver can look them up.
  3. Step 3: SPF: the allowed servers. When a message arrives, the receiver notes the IP address it came from and fetches the SPF record of the sending domain. Here the list holds one address, and -all means every other address fails. The real server at 192.0.2.10 passes. The forger at 203.0.113.66 is not on the list.
  4. Step 4: DKIM: a signature. The real server also signs each message. It hashes the body and chosen headers, signs the hash with a private key only it holds, and adds the result as a DKIM-Signature header naming the domain (d) and a selector (s). The receiver fetches the matching public key from DNS and checks it. A forged or altered message cannot pass.
  5. Step 5: The gap: whose domain?. SPF and DKIM each prove something about a domain, but maybe not the one the reader sees. SPF looks at the hidden envelope sender used for bounces, DKIM at whatever domain signed. A forger can pass both for his own domain, other.example, and still write example.com in the From line. DMARC closes this gap by demanding alignment.
  6. Step 6: DMARC: the policy. The DMARC record tells receivers what the owner wants done with mail that claims the domain but has no aligned pass. p=none only asks for reports, which is how owners start. p=quarantine sends failures to spam, and p=reject refuses them. The rua address receives summaries of who has been sending mail in the domain’s name.
  7. Step 7: Real passes, forgery fails. The receiver now has a rule. Real mail from example.com passes SPF and DKIM for the same domain as its From line, so it is delivered. The forger sending from his own address fails both checks. The forger who passes them for other.example is not aligned. Under p=reject both forgeries are refused before anyone reads them.
VALUES SO FAR
Fromexample.comclaimed
forger203.0.113.66IP
SPF····DNS
DKIM····signed
selector····DNS
aligned····rule
DMARC····policy
forgery····result

Spotted a mistake on this page?