You've bought a domain, set up hello@yourdomain.com, and sent your first email. Then it lands in spam. Or worse, it never arrives.
Most of the time the fix is three DNS records: SPF, DKIM and DMARC. I set these up for my own startup's domain recently, made a couple of mistakes along the way, and wrote down what actually worked. This guide walks through each record in the order you should add them.
What these three records do (in one minute)
Think of an email like a letter:
- SPF is a list of post offices allowed to send letters for your domain.
- DKIM is a wax seal on each letter that proves nobody changed it on the way.
- DMARC tells the receiving post office what to do if a letter fails those checks, and sends you reports about it.
Gmail and Yahoo now expect bulk senders to have all three, and even small senders get better delivery with them. Without them, anyone can pretend to send email as your domain.
Before you start
You need two things:
- Access to your domain's DNS settings. This is wherever your domain's nameservers point: your registrar, your hosting provider, Cloudflare, Vercel, and so on.
-
A list of every service that sends email as your domain. This is the step people skip. Usually it's at least two:
- Your mailbox provider (Google Workspace, Zoho Mail, Microsoft 365) for normal emails.
- Your app or marketing sender for order confirmations, password resets or newsletters.
Write the list down. Every service on it needs to appear in SPF and needs its own DKIM key.
Step 0: Check your MX records first
MX records tell the world where to deliver email for your domain. Your mailbox provider gives you these when you set up your inbox. They look like this:
| Type | Host | Value | Priority |
|---|---|---|---|
| MX | @ | mx.yourmailprovider.com | 10 |
| MX | @ | mx2.yourmailprovider.com | 20 |
A mistake I hit: my DNS records were being added through an API, and the priority field had a different name than I expected. The records saved without errors but didn't work. If email isn't arriving, look up your MX records with a public checker before blaming anything else.
Step 1: Add SPF
SPF is a single TXT record on your root domain (@).
v=spf1 include:_spf.yourmailprovider.com include:sendingservice.com ~all
How to read it:
-
v=spf1means "this is an SPF record". - Each
include:adds one service that's allowed to send for you. Your providers tell you exactly what to put here. -
~allmeans "anything else is suspicious" (a soft fail). Once you're confident everything is listed, you can switch to-all(hard fail).
Rules that trip people up:
-
Only one SPF record per domain. Two separate
v=spf1records break SPF completely. If you add a new sender, edit the existing record and add anotherinclude:. -
Maximum 10 DNS lookups. Each
include:costs at least one lookup, and some include others inside them. Too many senders and SPF fails. If you're close, remove services you no longer use. - It goes on
@(the root), not on a subdomain, unless you send from that subdomain.
Step 2: Add DKIM
DKIM is a cryptographic signature added to every email. Each sending service generates its own key pair. You publish the public key in DNS, and the service signs your emails with the private key.
- In each sending service, find the DKIM or "domain authentication" setting.
- It gives you a record to add. It's usually a TXT record like this:
Host: selector1._domainkey
Type: TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
Some services give you a CNAME instead, pointing to a key they host. Use exactly what they give you.
- The
selector1part is the "selector". Every service uses a different one, so several DKIM records can live side by side without clashing. - Go back to the service and click Verify, then make sure signing is switched on. Some services publish the key but don't sign until you enable it.
Repeat this for every service on your list. One DKIM record for your inbox provider doesn't cover your app's transactional emails.
Tip: long DKIM keys sometimes get split or truncated by DNS panels. If verification fails, check that the whole key was pasted as one value, with no extra spaces or quotes.
Step 3: Add DMARC
DMARC is a TXT record on the _dmarc host. Start in monitoring mode:
Host: _dmarc
Type: TXT
Value: v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com
-
p=nonemeans "don't block anything yet, just report". Always start here. -
rua=is where receiving servers send daily summary reports. Use an address you actually check, or a free DMARC report tool that reads them for you.
DMARC passes only when SPF or DKIM passes and the domain they check matches the domain in the visible "From" address. This "alignment" rule catches a common mistake.
The mistake I almost shipped: my app's email code had a default "From" address on a different domain than the one I'd authenticated. SPF and DKIM were set up perfectly for the right domain, but the emails claimed to come from another one, so they'd never align. Check the actual From address your app uses in production, not just your DNS.
Tightening DMARC later
After a week or two of clean reports showing all your real senders passing:
- Move to
p=quarantine(failures go to spam). - Later, move to
p=reject(failures are refused).
Don't jump straight to reject on a new domain. If you forgot a sender, its emails will vanish.
Step 4: Test it
DNS changes can take from a few minutes to a few hours to spread.
- Send an email from each sending service to a Gmail address.
- In Gmail, open the email, click the three dots, then Show original.
- Look for three lines near the top:
SPF: PASS
DKIM: 'PASS' with domain yourdomain.com
DMARC: 'PASS'
If one fails, the message headers usually say why: a missing include:, a DKIM selector that isn't published, or a From domain that doesn't align.
You can also run your domain through any public SPF, DKIM or DMARC checker to catch syntax errors before sending.
Quick checklist
- [ ] MX records point to your mailbox provider
- [ ] One SPF record on
@, with aninclude:for every sender, under 10 lookups - [ ] A DKIM record for each sending service, verified and signing switched on
- [ ] A DMARC record on
_dmarc, starting withp=noneand a report address - [ ] Your app's real "From" address uses the same domain you authenticated
- [ ] Test emails from every service show SPF, DKIM and DMARC as PASS
- [ ] After 1–2 weeks of clean reports, tighten DMARC to
quarantine, thenreject
Wrapping up
These three records take maybe 30 minutes to set up, and they're the difference between "your email is in their inbox" and "your email is in spam, or someone is sending phishing emails as you".
I'm building Namelume, a domain registration service for small businesses in India, and email setup is one of the first things new domain owners get stuck on. If you hit a problem not covered here, leave a comment and I'll try to help.
Top comments (0)