Email authentication explained with SPF, DKIM and DMARC

How a receiving mail server decides whether a message really comes from the domain in its From line. Three DNS records explained with examples, one message followed through every check, a safe roll-out plan, common mistakes and a short quiz, for IT and information systems classes.

Guide1 hBachelor +2CC BY 4.0

What you will learn

  • Explain why the From address of an email can be forged
  • Read an SPF, a DKIM and a DMARC record
  • Explain alignment and what a DMARC policy asks receivers to do
  • Read an Authentication-Results header
  • Plan the order in which a domain introduces the three records
  • Find these records for a real domain

Before you start: A basic idea of what DNS does: it turns names into addresses and other records.

The problem

Email was designed without proof of sender. The From line is just text: anyone can write ceo@example.com there. Phishing relies on exactly that. Three records published in the sender's DNS let a receiving server check a message instead of trusting it.

An email actually carries two sender addresses:

  • The envelope sender (also called Return-Path or bounce address) is used by the servers to deliver the message and to return bounces. Readers rarely see it.

  • The From address is what the reader sees in the mail app.

They can differ, for example when a newsletter service sends on a company's behalf. Keep the two apart: SPF checks one, DMARC protects the other.

SPF: which servers may send

SPF (Sender Policy Framework, RFC 7208) is a TXT record on the domain that lists the servers allowed to send its mail.

SPF record for example.com
example.com.  TXT  "v=spf1 include:_spf.mailprovider.example ip4:203.0.113.10 ~all"
  • include: adds the servers of a mail provider.

  • ip4: allows one address, here a company's own server.

  • ~all says: anything else is suspicious (soft fail). -all says: anything else fails (hard fail), and many receivers then refuse it.

The check uses the envelope sender (the Return-Path), not the visible From line. SPF also allows at most 10 DNS lookups; a record with more breaks. A domain may publish only one SPF record.

DKIM: a signature on the message

DKIM (DomainKeys Identified Mail, RFC 6376) signs each message. The sending server adds a DKIM-Signature header; the matching public key sits in DNS under a selector.

DKIM key under the selector "mail2026"
mail2026._domainkey.example.com.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...IDAQAB"

The signature names its domain (d=example.com) and selector (s=mail2026). If the message was changed on the way, the signature no longer verifies. Unlike SPF, DKIM survives forwarding, because it travels with the message instead of depending on the server that delivers it. Selectors let a domain use several keys at once, for example one per sending service, and replace old keys without a break.

DMARC: what to do when checks fail

DMARC (Domain-based Message Authentication, Reporting and Conformance) ties the two to the visible From domain and tells receivers what the owner wants done with failures. It was first described in RFC 7489 in 2015; in 2026 the IETF replaced that with RFC 9989, now on the standards track. Records still start with v=DMARC1, and records written for the old version keep working.

DMARC record for example.com
_dmarc.example.com.  TXT  "v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@example.com"
  • A message passes DMARC when SPF or DKIM passes and its domain matches (aligns with) the From domain.

  • p=none only asks for reports, p=quarantine asks to treat failures as spam, p=reject asks to refuse them.

  • rua= is where receivers send daily summary reports.

Alignment is relaxed by default: bounces.example.com aligns with example.com, because both belong to the same organisation's domain. With strict alignment (aspf=s or adkim=s) the names must be identical.

Follow one message

Fabrikam sends a newsletter with the From address news@fabrikam.example. The newsletter goes out through a mail service, which uses the bounce address bounces@mail.fabrikam.example and signs with DKIM for fabrikam.example. The receiving server:

  1. Looks up the SPF record of mail.fabrikam.example (the envelope sender's domain) and checks that the sending server's IP address is listed. SPF: pass.

  2. Reads the DKIM-Signature header, fetches the public key for the selector from DNS and verifies the signature. DKIM: pass for fabrikam.example.

  3. Looks up _dmarc.fabrikam.example and checks alignment: the SPF domain mail.fabrikam.example aligns in relaxed mode, and the DKIM domain matches exactly. DMARC: pass.

  4. Writes the results into the message and moves on to its own spam checks.

What the receiver writes into the message
Authentication-Results: mx.receiver.example;
  spf=pass smtp.mailfrom=mail.fabrikam.example;
  dkim=pass header.d=fabrikam.example header.s=news1;
  dmarc=pass header.from=fabrikam.example

Now a forger sends from their own server with From: news@fabrikam.example. Their server is not in Fabrikam's SPF record, and they have no private key to sign with. SPF and DKIM fail for Fabrikam's domain, so DMARC fails, and the receiver applies Fabrikam's policy.

Introducing the records safely

Switching straight to p=reject can block a company's own invoices or support emails. The usual order:

  1. List every service that sends as your domain: the office mail system, the newsletter tool, the shop, the invoicing software, the helpdesk.

  2. Add each one to SPF and keep the record under 10 lookups.

  3. Switch on DKIM for each service, with your own domain in d=.

  4. Publish DMARC with p=none and a rua= address, then read the reports for a few weeks.

  5. Fix whatever the reports show failing, then move to p=quarantine and later to p=reject.

Large mailbox providers now expect this. Since February 2024, Google requires SPF, DKIM and DMARC from anyone sending more than 5,000 messages a day to Gmail addresses, together with alignment, one-click unsubscribe for marketing mail and a low spam rate (Google's sender guidelines). Yahoo and Microsoft (for Outlook.com and Hotmail addresses) have published similar rules.

Common mistakes

  • Two SPF records. Adding a second v=spf1 record for a new service breaks both. Add the service to the one record instead.

  • Too many lookups. Every include: can contain further lookups. Above 10, SPF returns an error.

  • A forgotten sender. The invoicing tool was never added, so invoices fail DMARC once the policy is strict.

  • Going to p=reject on day one. Start with p=none and read the reports.

  • No one reads the reports. A rua= address that nobody checks wastes the monitoring step.

  • Thinking a pass means the inbox. Authentication proves who sent a message. Whether it is wanted is a separate question, judged by complaints, bounces and content.

Exercise

  1. Use the Mailbox Provider Checker to find who receives email for your school's or university's domain.

  2. Look up its SPF and DMARC records with any DNS lookup tool or nslookup -type=TXT _dmarc.yourdomain in a terminal.

  3. Answer: which policy does the domain publish? What would happen to a forged message with its name in the From line?

Quiz

Check yourself

6 questions
  1. 1.Which address does SPF check?

  2. 2.Why does DKIM usually survive forwarding while SPF does not?

  3. 3.What does DMARC need to pass?

  4. 4.A company publishes p=none. What does it ask receivers to do with failing messages?

  5. 5.A company adds a second TXT record starting with v=spf1 for its new newsletter tool. What happens?

  6. 6.In which order should a company introduce the records?

Key terms

  • Envelope sender: the address the sending servers use for bounces, checked by SPF.

  • Selector: the label that tells a receiver which DKIM key to fetch.

  • Alignment: the SPF or DKIM domain matches the From domain.

  • Policy: the p= value in DMARC: none, quarantine or reject.

  • Aggregate report: the daily summary a receiver sends to the rua= address, listing which servers sent mail as the domain and whether it passed.

Practise it with the SPF, DKIM and DMARC check.

Reuse this material

CC BY 4.0

You may copy, adapt and share it, also commercially, as long as you credit ManyPI and link back.

"Email authentication explained with SPF, DKIM and DMARC" by ManyPI (https://manypi.com/edu/email-authentication-spf-dkim-dmarc), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)