All posts

Blog

SPF, DKIM and DMARC Explained: How to Stop Your Emails Landing in Spam

Illustrated cover for the Email guide "SPF, DKIM and DMARC Explained: How to Stop Your Emails Landing in Spam"

If your emails keep landing in customers' spam folders, or someone has been sending fake emails "from" your domain, the fix usually involves three DNS records: SPF, DKIM and DMARC.

Major mailbox providers such as Gmail and Yahoo now expect senders to authenticate their mail, and requirements are strictest for bulk senders. Even if you only send a few emails a day, setting these up properly helps your messages get delivered.

The problem these records solve

Email was designed decades ago without any built-in way to prove who sent a message. Anyone can put ceo@yourbusiness.com in the "From" line. SPF, DKIM and DMARC let receiving servers check whether a message really came from you.

SPF: who is allowed to send

SPF (Sender Policy Framework) is a TXT record listing the servers allowed to send email for your domain.

Example:

v=spf1 a mx include:_spf.example-service.com ~all

In plain English:

  • v=spf1: this is an SPF record
  • a and mx: servers listed in my A and MX records may send
  • include:...: also allow this email service's servers
  • ~all: anything else should be treated as suspicious (a "soft fail")

SPF rules to know

  • Only one SPF record per domain. Two SPF records make SPF fail. If you use several services, merge them into one record with several include: entries.
  • There's a limit of 10 DNS lookups. Each include, a and mx counts. Too many services can break SPF.
  • ~all vs -all: ~all (soft fail) is the safer default. -all (hard fail) is stricter. Only use it once you're sure every sender is listed.

DKIM: a digital signature

DKIM (DomainKeys Identified Mail) adds a cryptographic signature to every email you send. The receiving server looks up a public key in your DNS and checks the signature. If the message was altered or forged, the check fails.

A DKIM record lives under a "selector" name, like:

default._domainkey.yourdomain.com  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."

You don't write DKIM keys yourself. Your email provider generates them. Each sending service you use, such as your hosting mailbox or a newsletter tool, should have its own DKIM key.

DMARC: your policy and your reports

DMARC (Domain-based Message Authentication, Reporting and Conformance) ties SPF and DKIM together. It tells receiving servers:

  1. What to do with mail that fails the checks
  2. Where to send reports about mail claiming to be from your domain

It's a TXT record at _dmarc.yourdomain.com:

v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com
  • p=none: monitor only, don't block anything yet
  • p=quarantine: send failing mail to spam
  • p=reject: block failing mail entirely
  • rua=: where to send aggregate reports

DMARC also checks alignment: the domain in the visible "From" address must match the domain that passed SPF or DKIM. This is what stops look-alike spoofing.

How to set them up

If your domain uses your web host's nameservers

Your hosting DNS zone usually includes SPF and DKIM for your hosting mailboxes already. To check in cPanel, look at Email Deliverability, which shows the status of each domain and suggests fixes. In DirectAdmin, check DNS Management for a TXT record starting v=spf1 and a _domainkey record.

Then add DMARC:

  1. Open Zone Editor in cPanel or DNS Management in DirectAdmin.
  2. Add a TXT record with the name _dmarc and the value v=DMARC1; p=none; rua=mailto:you@yourdomain.com.
  3. Save.

If you use other email services too

If you send through other services, such as a newsletter platform, a help desk or an online store, each needs:

  • An include: added to your single SPF record
  • Its own DKIM record, which the service gives you

Ask each service for its exact records, and merge SPF entries carefully.

Rolling out DMARC safely

Jumping straight to p=reject can block your own legitimate mail if a service isn't set up correctly. Do it in stages:

  1. Start with p=none and collect reports for a few weeks.
  2. Review the reports. A DMARC report reader service makes the raw XML easy to understand. Look for legitimate services that fail.
  3. Fix any failing senders by adding their SPF include and DKIM.
  4. Move to p=quarantine, optionally with pct= to apply it to a percentage of mail first.
  5. Move to p=reject when you're confident.

Many small businesses happily stay at quarantine. Any policy beyond none protects your domain from spoofing much better than no DMARC at all.

How to check your records

  • Send a test email to a Gmail address, open it, and choose Show original. You'll see PASS or FAIL for SPF, DKIM and DMARC.
  • Use an online checker for SPF, DKIM and DMARC. Many free tools exist.
  • Command line:
nslookup -type=txt yourdomain.com
nslookup -type=txt _dmarc.yourdomain.com

Common mistakes

  • Two SPF records instead of one combined record
  • Forgetting a sending service, such as a contact form plugin sending through a third-party service
  • Going straight to p=reject
  • Records added at the wrong DNS provider. Edit DNS where your nameservers point. See nameservers vs DNS records.

The bottom line

SPF says who may send, DKIM proves messages weren't forged, and DMARC tells the world what to do when checks fail. Make sure you have one SPF record, DKIM for every service, and a DMARC policy that starts at none and tightens over time. For other causes of spam-folder trouble, see why your emails go to spam.