Samprix

Guide

SPF, DKIM and DMARC explained

What each record does, how they work together, and the order to set them up in.

Updated

Email was designed without any way to prove who sent a message. Anyone can put ceo@yourcompany.com in the From line. SPF, DKIM and DMARC are three DNS records that close that gap. Together they let a receiving mail server check that a message really comes from your domain, and tell it what to do when it doesn’t.

They also decide a lot of your deliverability. Gmail, Yahoo and Microsoft now require all three from anyone sending in bulk, and mail without them is far more likely to land in spam or be refused.

SPF: which servers may send

SPF (Sender Policy Framework) is a TXT record at your domain listing the servers allowed to send email for it:

v=spf1 include:_spf.google.com include:sendgrid.net ~all

This one says “Google Workspace’s servers and SendGrid’s servers may send for us; treat everything else with suspicion (~all)”. A receiving server checks the IP address of the server that connected to it against that list.

Its limits: SPF checks the domain in the hidden return path (the “envelope from”), not the From address people see, and it breaks when mail is forwarded, because the forwarding server isn’t on your list. It also allows only 10 DNS lookups; see fixing too many DNS lookups.

DKIM: a signature on every message

With DKIM (DomainKeys Identified Mail), your email service adds a cryptographic signature to each message’s headers. The public key that verifies it is published in DNS at selector._domainkey.yourdomain.com. If the signature checks out, the receiver knows the message was sent by someone holding your private key and wasn’t changed on the way.

DKIM survives forwarding, which makes it the more reliable of the two. You don’t write the record yourself: you turn DKIM on in each email service’s settings, and it gives you the record to publish. The selector lets each service have its own key; see how to find your DKIM selector.

DMARC: the policy that ties them together

SPF and DKIM on their own don’t protect the From address. A spammer can send from their own domain with perfect SPF and DKIM and still put your domain in the From line. DMARC fixes that with alignment: a message passes DMARC only if SPF or DKIM passes for the same domain as the From address.

DMARC is a TXT record at _dmarc.yourdomain.com:

v=DMARC1; p=quarantine; rua=mailto:dmarc@yourdomain.com

p= is the policy for mail that fails: none (deliver anyway, just report), quarantine (spam folder) or reject (refuse). rua= is where receivers send daily reports of every server that sent mail as your domain, which is how you find out what you’d break before you tighten the policy.

How a receiver uses all three

  1. A message arrives claiming to be from you@example.com.
  2. The receiver checks SPF for the return-path domain and verifies any DKIM signatures.
  3. It looks up _dmarc.example.com and checks whether either passing result is for example.com (or a subdomain of it, with the default relaxed alignment).
  4. If one is, DMARC passes. If neither is, it applies your policy and records the result in the report it sends you.

The order to set them up

  1. List every service that sends as your domain: your mailbox provider, your newsletter tool, your CRM, your helpdesk, your website’s contact form, your billing system.
  2. Publish one SPF record with an include for each, ending in ~all.
  3. Turn on DKIM in each service, signing with your own domain, and publish the records they give you.
  4. Publish DMARC at p=none with a report address, and read the reports for two to four weeks.
  5. Tighten to quarantine, then reject once every legitimate source passes. Step-by-step: moving DMARC from none to reject.

Domains that never send email

Parked domains and domains used only for a website are favourite targets for spoofing, because nobody watches them. Lock them down with two records:

example.com         TXT  "v=spf1 -all"
_dmarc.example.com  TXT  "v=DMARC1; p=reject"

The first says no server may send for the domain; the second tells receivers to refuse anything that claims to.

All tools