SPF, DKIM and DMARC explained
Three DNS checks stop others sending email that pretends to be from your domain. What each does, how they fit together, and how to roll them out safely.
Email was designed when everyone on the network knew everyone else. Nothing in the original protocol stops a stranger typing anyone's address into the "From" line. SPF, DKIM and DMARC are the add-ons that, decades later, let a receiving mail server ask: "Is this message really allowed to claim this domain?"
If you own a domain, this matters twice. It protects your customers from fake emails in your name, and it helps your genuine emails reach inboxes instead of spam folders.
Two different "from" addresses
The trick to understanding all three is that every email has two sender addresses:
- The envelope sender (also called MAIL FROM or Return-Path). It is used behind the scenes to route bounces. You never see it.
- The header From, the address your mail app displays.
They can differ, and spoofers exploit that. SPF checks the first, DKIM signs the message under its own domain, and DMARC is the rule that connects both back to the address people actually see.
SPF: who may send for this domain?
SPF (RFC 7208) is a list, published in DNS, of the servers allowed to send mail for a domain. The receiving server looks at the connecting IP address and checks it against the list for the envelope sender's domain.
example.org. IN TXT "v=spf1 include:spf.protection.outlook.com -all"Read it left to right: this is SPF version 1, include the senders that Microsoft publishes for Exchange Online, and -all means "reject anything else". A softer ending, ~all, means "treat anything else with suspicion".
Things to know:
- A domain must have only one SPF record. Two records make SPF invalid.
- SPF allows at most ten DNS lookups while evaluating a record. Stacking up
include:entries for every service you use can break this limit without you noticing. - SPF breaks when mail is forwarded, because the forwarding server's IP address is not on your list.
DKIM: a signature on the message
DKIM (RFC 6376) works like a wax seal. Your sending server signs selected headers and the body with a private key. The matching public key sits in DNS, under a name made from a selector and your domain. The receiver fetches the key and checks the signature.
The signature travels with the message in a header, which looks roughly like this (shortened):
DKIM-Signature: v=1; a=rsa-sha256; d=example.org; s=selector1;
h=from:to:subject:date; bh=...; b=...Here d= is the domain that signed and s= is the selector. Because the signature is part of the message, it normally survives forwarding, unless something along the way changes the signed parts. Mailing lists that add footers often do.
With Microsoft 365, the public keys are published as two CNAME records that point to Microsoft-hosted keys, which lets Microsoft rotate them for you:
selector1._domainkey.example.org. IN CNAME selector1-example-org._domainkey.yourtenant.onmicrosoft.com.
selector2._domainkey.example.org. IN CNAME selector2-example-org._domainkey.yourtenant.onmicrosoft.com.The exact values for your domain are shown when you enable DKIM in the Microsoft Defender portal. Copy them from there rather than from this article.
DMARC: the rule that ties it together
SPF and DKIM each prove something, but neither proves anything about the address people see. DMARC (RFC 7489) adds two things:
- Alignment. A message passes DMARC only if SPF or DKIM passes and the domain that passed matches the header From domain.
- A policy and reporting. You tell receivers what to do with failures and where to send reports.
_dmarc.example.org. IN TXT "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.org"The p= policy has three settings:
| Policy | What receivers are asked to do with failures |
|---|---|
p=none | Deliver as normal, but send you reports |
p=quarantine | Treat as suspicious, usually the spam folder |
p=reject | Refuse the message |
The rua= address receives daily summary reports (in XML) showing who is sending mail as your domain and whether it passed. Those reports are the whole point of starting with p=none.
How the three fit together
| Check | Proves | Breaks when |
|---|---|---|
| SPF | The sending server's IP is on your list | Mail is forwarded |
| DKIM | The message was signed by your domain and not altered | A middleman edits the message |
| DMARC | One of the above passed and matches the visible From | Neither passes in alignment |
When all is well, the receiving server records the verdicts in a header you can read yourself. This one is an illustration, not a real message:
Authentication-Results: mx.example.net;
spf=pass smtp.mailfrom=example.org;
dkim=pass header.d=example.org header.s=selector1;
dmarc=pass header.from=example.orgLooking at your own domain
You can see your published records from any terminal:
dig +short TXT example.org
dig +short TXT _dmarc.example.org
dig +short CNAME selector1._domainkey.example.orgOn Windows, nslookup -type=TXT example.org does the same job. Swap in your own domain. To see the verdicts on real mail, open a message you received and look at its full headers for Authentication-Results.
A safe order of work
- List every service that sends email as your domain. Your mailbox provider, yes, but also invoicing software, website contact forms, booking tools and mailing-list services. Forgotten senders are the usual reason legitimate mail starts failing.
- Publish one SPF record covering them all, and keep an eye on the ten-lookup limit.
- Turn on DKIM for your main provider and for each other service that supports it.
- Publish DMARC with
p=noneand a reporting address. Leave it for a few weeks and read the reports. - Fix what the reports reveal, then move to
p=quarantine, and later top=rejectonce genuine mail is consistently passing.
Skipping straight to p=reject is how businesses discover, a day too late, that their invoicing system was sending as their domain.
What this does not do
DMARC protects your exact domain. It does not stop someone registering a lookalike such as examp1e.org, and it does nothing about a "From" display name that says "Your Boss" but uses a free webmail address. It also cannot help if a genuine mailbox has been taken over. These checks are one layer, not the whole defence.
Why it matters beyond spoofing
Large mailbox providers have been tightening their rules. Google's sender guidelines, for example, set authentication requirements for senders who mail Gmail users in bulk, and recommend SPF and DKIM for everyone. Check the current wording on their page, as these requirements have changed over time.
If you use Microsoft 365, Microsoft's three setup guides, linked in the sources below, walk through each record in the admin portals.
Sources
- RFC 7208, Sender Policy Framework (SPF) www.rfc-editor.org
- RFC 6376, DomainKeys Identified Mail (DKIM) Signatures www.rfc-editor.org
- RFC 7489, Domain-based Message Authentication, Reporting, and Conformance (DMARC) www.rfc-editor.org
- IETF Datatracker entry for RFC 7489 (shows any later revision) datatracker.ietf.org
- NCSC, Email security and anti-spoofing www.ncsc.gov.uk
- Microsoft Learn, Set up SPF to help prevent spoofing learn.microsoft.com
- Microsoft Learn, Use DKIM for email in your custom domain learn.microsoft.com
- Microsoft Learn, Use DMARC to validate email learn.microsoft.com
- Google, Email sender guidelines support.google.com