DEV Community

Rishav Mandal
Rishav Mandal

Posted on Originally published at promptpost.io AI-assisted

SPF, DKIM and DMARC Explained Without the Jargon

Key takeaways

  • SPF, DKIM and DMARC are DNS records that prove your email really comes from your domain.
  • SPF lists allowed senders, DKIM signs messages so tampering is detectable, and DMARC tells receivers what to do when checks fail.
  • Publish one SPF record, enable DKIM for every sender, start DMARC at p=none, read the reports, then tighten to quarantine or reject.

You built a beautiful email template. The signup flow works. Then a new user writes in: "I never got the verification email." It's sitting in their spam folder, or it never arrived at all.

Content and design rarely cause this. The usual culprit is that your domain hasn't proved the email really came from you. Since 2024, the largest mailbox providers have required bulk senders to authenticate their mail, and unauthenticated messages from new domains are increasingly treated with suspicion even at low volume.

Three DNS records fix most of it: SPF, DKIM and DMARC. Here's what each one does, in plain words.

The problem: email has no built-in identity

The email protocol was designed in an era of trust. Anyone can send a message claiming to be from support@yourbank.com. Without extra checks, the receiving server has no way to know whether it's genuine.

SPF, DKIM and DMARC are three layers added later to answer one question: is this sender allowed to send mail for this domain, and was the message tampered with?

SPF: the guest list

Sender Policy Framework is a list, published in your DNS, of the servers allowed to send email for your domain.

When Gmail receives a message claiming to be from your domain, it looks up your SPF record and checks whether the sending server is on the list.

A typical SPF record is a TXT record on your root domain:

v=spf1 include:_spf.example-mailhost.com ~all
Enter fullscreen mode Exit fullscreen mode
  • v=spf1 marks it as an SPF record.
  • include: adds your email provider's servers to the guest list.
  • ~all says "anyone else is suspicious" (a soft fail). -all is the strict version.

Two common mistakes:

  • Two SPF records. You may only have one. If you use several services (a mailbox provider plus a newsletter tool), merge them into one record with several include: entries.
  • Too many lookups. SPF allows at most ten DNS lookups. Each include can contain more, so a long list can quietly exceed the limit and break validation.

DKIM: the tamper-proof seal

DomainKeys Identified Mail adds a cryptographic signature to every outgoing email. Your mail provider signs messages with a private key; you publish the matching public key in DNS.

The receiving server fetches the public key and checks the signature. If it matches, two things are proven: the message was signed by someone authorised for your domain, and the content wasn't altered in transit.

You usually don't write DKIM records by hand. Your email provider generates the key and gives you a TXT or CNAME record to add, at a name like selector._domainkey.yourdomain.com. Many hosting panels have a one-click "enable DKIM" option that publishes it for you.

DMARC: the policy and the reporting

SPF and DKIM produce results, but they don't tell the receiver what to do when a check fails. DMARC (Domain-based Message Authentication, Reporting and Conformance) does.

It also adds an important rule called alignment: the domain the reader sees in the "From" line must match the domain that passed SPF or DKIM. Without alignment, a spammer could pass SPF with their own domain while displaying yours.

A starter DMARC record, as a TXT record at _dmarc.yourdomain.com:

v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com
Enter fullscreen mode Exit fullscreen mode
  • p=none means "don't block anything yet, just report."
  • rua= is where receivers send daily aggregate reports.

Once reports show your legitimate mail passing consistently, tighten the policy step by step: p=quarantine (send failures to spam), then p=reject (refuse them outright).

Setting it up: the order that works

  1. Inventory your senders. List every service that sends email as your domain: your mailbox host, your app's transactional mail, newsletter tools, support desks, invoicing software.
  2. Publish one SPF record that includes all of them.
  3. Enable DKIM for each sending service, using the records each provider gives you.
  4. Add DMARC at p=none with a reporting address.
  5. Wait and read the reports for two to four weeks. They'll reveal senders you forgot about.
  6. Tighten DMARC to quarantine, then reject, once everything legitimate passes.

DNS changes can take anywhere from minutes to a day to propagate, so don't panic if checks fail immediately.

How to test

  • Send a message to a deliverability tester such as mail-tester.com. It scores your setup and lists exactly what's missing.
  • In Gmail, open a message you sent, choose "Show original," and look for SPF: PASS, DKIM: PASS and DMARC: PASS.
  • Query your records from a terminal: dig txt yourdomain.com +short and dig txt _dmarc.yourdomain.com +short.

Symptoms that point to authentication problems

  • Messages arrive at some providers but land in spam at others.
  • Recipients see warnings such as "this message may not be from who it claims."
  • Deliverability testers report missing or failing records.
  • Messages from your app work, but emails sent from a newsletter tool on the same domain don't. That's usually a sign that one sender is missing from SPF or has no DKIM.

Beyond authentication

Authentication gets you through the door; reputation keeps you there. A few habits matter:

  • Send transactional mail (password resets, receipts) from a consistent, dedicated address.
  • Don't send marketing blasts from the same setup that sends security emails.
  • Include a plain-text version of every HTML email.
  • Make unsubscribing easy for anything non-essential.
  • Never buy email lists.

The short version

SPF says who may send. DKIM proves the message is genuine and unchanged. DMARC says what to do when either fails and makes sure the visible sender lines up with the checks.

Set up all three, start DMARC in monitoring mode, read the reports, then tighten. It's an afternoon of DNS work that saves you months of "check your spam folder" support replies.

Related reading: Laravel queues and cron on shared hosting ยท India's DPDP rules: what startups should do now

FAQ

What is the difference between SPF, DKIM and DMARC?
SPF lists which servers may send email for your domain. DKIM adds a cryptographic signature proving the message wasn't altered. DMARC sets the policy for failures and requires the visible From domain to align with SPF or DKIM.

Why are my emails going to spam?
Missing or failing authentication is the most common technical reason, especially for new domains. Check your SPF, DKIM and DMARC records with a deliverability tester.

Can I have two SPF records?
No. A domain must have only one SPF record. Merge multiple senders into a single record with several include entries.

Which DMARC policy should I start with?
Start with p=none to collect reports without blocking mail. Move to p=quarantine and then p=reject once all legitimate senders pass.


Originally published on PromptPost.

Written by me, reviewed with the help of AI.

Top comments (0)