How Email Finds Its Way, and Why SPF, DKIM and DMARC Exist
Email is old. Older than the web. And it was designed for a small network of people who mostly trusted each other, which explains a lot about why it's such a mess today. The original protocol lets anyone claim to be anyone. You could write From: ceo@yourcompany.com on a message and nothing in the basic system would stop you.
SPF, DKIM and DMARC are the three add-ons that fix that, bolted on over the years. If you own a domain and send email from it, or you're wondering why your messages keep landing in spam, these are what you need to understand. First, though, a quick look at how a message gets anywhere.
The delivery part
When you hit send, your email app hands the message to your provider's outgoing mail server using SMTP. That server looks at the recipient's address, say someone@example.org, and does a DNS lookup for the MX records of example.org. MX records say which servers accept mail for that domain. Your provider connects to one of them and hands the message over, again using SMTP. The receiving server decides whether to accept it, where to file it, and whether it smells like spam. Then the recipient's app fetches it with IMAP or a provider's own API.
Notice what's missing. At no point in that chain does anything check whether the sender was actually allowed to send as that address. That's the gap.
SPF: who's allowed to send
Sender Policy Framework is a DNS TXT record on your domain that lists which servers are allowed to send mail for it. A receiving server checks the sending server's IP address against your list.
example.com. TXT "v=spf1 include:_spf.yourmailprovider.example ~all"
That says: servers listed by my mail provider can send for me, and anything else should be treated as suspicious. The ending matters. ~all is a soft fail (suspicious, probably mark it), and -all is a hard fail (not authorized). Your mail provider will tell you exactly what to put in the include: part.
Two things that trip people up. You can only have one SPF record per domain, so if you add a newsletter service later, merge it into the existing record instead of adding a second one. And SPF has a limit of ten DNS lookups when it's evaluated. Stack up too many include: entries and the whole thing fails.
SPF's big weakness is forwarding. If someone forwards your message from another server, that server isn't on your list, and SPF fails even though nothing shady happened. It also checks the hidden "envelope" sender, not the From address you actually see. Which is why we need the other two.
DKIM: a signature on the message
DomainKeys Identified Mail has your sending server sign each outgoing message with a private key. The matching public key is published in DNS under a "selector" name:
selector1._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."
The receiving server reads the signature from the message headers, fetches the public key and checks it. If it verifies, two things are true: the message really came from a system that holds your private key, and the signed parts weren't changed along the way.
Because the signature travels inside the message, DKIM usually survives plain forwarding where SPF breaks. Things like mailing lists that rewrite subjects or add footers can still break it, though. Your provider generates the keys and gives you the record to publish. The private key stays with them, or on your own mail server if you run one, and never goes in DNS.
DMARC: tying it together
SPF and DKIM each prove something, but neither one says what a receiver should do when checks fail, and neither one on its own guarantees the visible From address is legit. DMARC handles both.
DMARC requires alignment. At least one of SPF or DKIM has to pass, and the domain it passed for has to match the domain in the From address people actually see. That closes the loophole where a spammer passes SPF for their own domain while putting yours in the From line.
It also lets you publish a policy:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com"
The p= part is the policy. none means just monitor, quarantine means send failures to spam, and reject means refuse them outright. The rua= address is where receiving servers send aggregate reports about mail they saw claiming to be from your domain, which is how you discover the newsletter tool or billing system you forgot was sending as you.
How I'd roll it out
- Set up SPF with every service that legitimately sends as your domain.
- Turn on DKIM signing with your mail provider and publish the record they give you. Do the same for other sending services that support it.
- Publish DMARC with
p=noneand a reporting address. A free or paid DMARC report service makes the reports, which are XML, much easier to read. - Watch the reports for a few weeks. Fix anything legitimate that's failing.
- Move to
p=quarantine, then eventuallyp=rejectonce you're confident.
Rushing straight to reject is the classic mistake. You'll block your own invoices or password reset emails and not know why.
One more tip that's easy to miss. If you own domains that never send email at all, lock them down so nobody can spoof them:
example.net. TXT "v=spf1 -all"
_dmarc.example.net. TXT "v=DMARC1; p=reject"
Big mailbox providers increasingly expect senders to have all three in place, and mail without them is more likely to end up in spam or get bounced. So even if spoofing isn't on your radar, deliverability probably is. Set these up once, check the reports every so often, and email from your domain will mostly just work.

Comments