DEV Community

Cover image for SPF, DKIM and DMARC Explained: Stop Emails Going to Spam
GeekSpark
GeekSpark

Posted on Originally published at geekspark.in

SPF, DKIM and DMARC Explained: Stop Emails Going to Spam

Your website sends a password reset. The customer says it never arrived. You send a quote from your business email, and it lands in the client's spam folder. Nothing looks wrong on your side. The email left, so where did it go?

Most of the time, the answer is three small DNS records: SPF, DKIM and DMARC. They are how Gmail, Outlook and every other mail provider decide whether an email really comes from you. If one of them is missing or broken, your email gets treated like a stranger at the door.

We learned this the hard way on our own site. We moved our domain's DNS to Cloudflare, everything looked fine, and then our contact form alerts quietly stopped arriving. The bounce message said: 550 5.7.1 Email rejected per DMARC policy. The cause turned out to be a single setting on two records. More on that below, because it catches a lot of people.

This guide explains the three records in plain language, shows what correct ones look like, and lists the mistakes we see most often. No email background needed.

The short version

Record What it answers Where it lives One-line example
SPF Which servers may send email for my domain? TXT record on your domain v=spf1 include:_spf.google.com ~all
DKIM Was this email really signed by my domain, and unchanged? TXT or CNAME at selector._domainkey v=DKIM1; k=rsa; p=MIIBIjAN...
DMARC What should receivers do when the checks fail? TXT record at _dmarc v=DMARC1; p=quarantine; rua=mailto:...

A simple way to remember it:

  • SPF is the guest list. It names the servers allowed to send on your behalf.
  • DKIM is the wax seal. Each email carries a signature that proves it came from you and was not changed on the way.
  • DMARC is the house rule. It tells receivers what to do with an email that fails, and sends you reports about it.

You want all three. Since 2024, Gmail and Yahoo require at least SPF or DKIM from everyone, and all three from anyone sending in bulk. Microsoft added similar rules for Outlook.com in 2025.

SPF: the guest list

SPF is one TXT record on your main domain. It lists every service that sends email with your domain in it. Here is a typical one for a business that uses Google Workspace for its inbox and SendGrid for its website and newsletter emails:

DKIM: the wax seal

When your email provider sends a message, it adds a digital signature to it using a private key that only the provider has. The matching public key sits in your DNS. The receiving server looks up that key and checks the signature. If it matches, the email is genuinely from your domain and nobody changed it on the way.

DMARC: the house rule

SPF and DKIM do the checking. DMARC decides what happens next. It is one TXT record at _dmarc.yourdomain.com:

How to check your own setup in two minutes

The easiest way: Gmail. Send an email from your business address to a Gmail account. Open it, click the three dots (⋮) and choose Show original. At the top you'll see SPF, DKIM and DMARC, each with PASS or FAIL. Three passes means your setup is right.

Moving your DNS? Use this checklist

Changing DNS provider is the moment email breaks most often, because records get missed, mangled or proxied during the import. Before you switch nameservers:

  • Export or screenshot every record at your old provider, especially MX, every TXT and every _domainkey record.
  • After the import, compare them line by line. Imports regularly drop or change records.
  • Set every mail record to DNS only if your new host offers a proxy. That covers MX targets, _domainkey CNAMEs and any mail or autodiscover records.
  • Check there is still exactly one SPF record, and that every include: still resolves.
  • Send a test to Gmail and check Show original right after the switch.

All three pass, but you're still in spam?

Then authentication is no longer the problem. Gmail is judging the email itself and your domain's track record. A few things help:

  • Give it a few days. A domain that just changed its setup, or sends rarely, has little reputation yet. Normal emails that get opened and replied to build it.
  • Mark it "Not spam" and add the sender to your contacts while testing. Gmail learns from that quickly.
  • Write like a person. One-line test messages, all caps, lots of links or link shorteners look like spam. A normal greeting and a couple of sentences do not.
  • Send newsletters through a proper service, with a working unsubscribe link, and only to people who asked for them. Gmail expects bulk senders to keep spam complaints well below 0.3%.

Sources


This is the short version. The full guide, with every step and source, is on GeekSpark.

Top comments (0)