SPF, DKIM and DMARC explained, and how to set them up so email reaches the inbox

· 2 min read

A plain explanation of SPF, DKIM and DMARC for domain owners, with the DNS records to add, how to check they pass and the mistakes people make most often.

SPF, DKIM and DMARC setup

Email has no built-in identity check: anyone can type your domain into the From line. SPF, DKIM and DMARC are three DNS records that let receivers tell your real mail apart from forgeries, and they are the baseline Gmail and Yahoo use to decide whether mail goes to the inbox.

Record Answers the question Where it lives
SPF Is this server allowed to send for this domain? TXT on the domain (or the return path)
DKIM Was the content changed on the way, and who signed it? TXT at <selector>._domainkey
DMARC What to do when SPF/DKIM fail TXT at _dmarc

SPF

SPF checks the domain in the envelope sender (Return-Path), not the From address people see. That's why the usual setup is a dedicated subdomain for the return path with a CNAME pointing to your provider. SPF then passes and is aligned with your domain, without touching the SPF record of your main domain.

send.example.com  CNAME  mta.bytesms.com

SPF allows at most 10 DNS lookups. Adding includes for several providers on your main domain can go over the limit and turn into a permerror. A separate return path avoids that.

DKIM

Your provider creates a key pair. The private key signs every message; you publish the public key as a TXT record, and receivers fetch it from DNS to check the signature. In Bytesms the selector is bytesms.

bytesms._domainkey.example.com  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."

DMARC

DMARC passes when SPF or DKIM passes and the passing domain matches the domain in From. It also tells receivers what to do with mail that fails, and sends you reports.

_dmarc.example.com  TXT  "v=DMARC1; p=none; rua=mailto:[email protected]"
  1. Start at p=none and collect reports for 2 to 4 weeks
  2. Check that every system sending for the domain passes DKIM or aligned SPF
  3. Move to p=quarantine, then to p=reject

Check your setup

  • Open a received email in Gmail, choose Show original, and look for PASS on SPF, DKIM and DMARC
  • Run dig TXT _dmarc.example.com to see whether the record is published
  • Some DNS providers take a few hours before changes are visible

Common mistakes

  • Two SPF records on one domain (merge them into one)
  • The DKIM value gets split across lines or wrapped in extra quotes
  • Cloudflare proxy (orange cloud) left on for the return path CNAME: it must be DNS only
  • Jumping straight to p=reject, so mail from systems you forgot to set up gets dropped

More articles