Skip to content

SPF, DKIM and DMARC explained: why your emails land in spam

· The AYT team · 9 min read

Colourful network cables plugged into a switch

SPF, DKIM and DMARC are three TXT records in your domain's DNS that let the receiving server check whether a message really comes from you. SPF says which servers may send on the domain's behalf, DKIM puts a verifiable signature on every message, and DMARC says what happens to messages that fail the checks. If they're missing or wrong, your messages land in spam or get rejected.

The big email providers now require them. Since February 2024, Gmail requires SPF or DKIM from every sender, and SPF, DKIM and DMARC from anyone sending more than 5,000 messages a day to Gmail accounts (Google's sender guidelines). Since May 2025, Microsoft has required SPF, DKIM and DMARC from anyone sending more than 5,000 messages a day to Outlook.com, Hotmail and Live.

What the receiving server checks

What the receiving server checks in an email: SPF for the sender's IP, DKIM for the signature and DMARC for the match with the From domain; if DMARC fails, the p= policy decides between spam and rejection

  1. SPF: is the IP of the server that sent the message in the list the domain publishes?
  2. DKIM: does the signature in the message header match the public key in the domain's DNS?
  3. DMARC: did at least one of the checks above pass, for the same domain as the one in the From field (the address the recipient sees)? If not, what policy did the domain ask for?

The last question matters most. An attacker can send a message from their own server with From: accounts@yourcompany.ro, with valid SPF and DKIM for their own domain. DMARC catches exactly this case, because it requires the passing check to be for yourcompany.ro, the domain in From.

SPF: who may send

SPF (Sender Policy Framework) is a TXT record on the domain listing the servers allowed to send email on its behalf:

yourcompany.ro.  TXT  "v=spf1 mx a include:_spf.google.com -all"
  • mx and a authorize the servers in the domain's MX and A records;
  • include: adds an external service's servers (Google Workspace, Microsoft 365, a newsletter platform);
  • ip4:203.0.113.10 authorizes a specific address;
  • at the end, -all asks for every other server to be rejected, while ~all only marks them as suspicious.

Rules many people trip over:

  • A domain has one SPF record. Two v=spf1 records make the check fail. When you add a new service, you add it to the same record.
  • SPF allows at most 10 DNS lookups per check (every include, a and mx counts). With too many services included, SPF returns an error and protects nothing.
  • SPF checks the address on the message's envelope (the Return-Path), not the From address. That's why, on its own, it doesn't stop sender spoofing.
  • When an email is forwarded, SPF usually fails, because the message leaves from another server. DKIM survives forwarding.

DKIM: the message's signature

DKIM (DomainKeys Identified Mail) signs every outgoing message with a private key kept on the mail server. The public key lives in DNS, at a name like selector._domainkey.yourcompany.ro:

mail._domainkey.yourcompany.ro.  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."

The selector (mail in the example) is chosen by the sending service. Each service has its own selector and key, so a domain can have several DKIM records without conflict. Use 2048-bit keys where your provider allows it.

The signature covers the important headers and the content. If someone changes the message on the way, the DKIM check fails.

DMARC: what happens when checks fail

DMARC (Domain-based Message Authentication, Reporting and Conformance) is a TXT record at _dmarc.yourcompany.ro:

_dmarc.yourcompany.ro.  TXT  "v=DMARC1; p=none; rua=mailto:dmarc@yourcompany.ro"
Policy What the receiving server does
p=none delivers the message as usual and only reports
p=quarantine puts messages that fail DMARC in spam
p=reject refuses messages that fail DMARC

The rua address receives daily XML reports from the big providers: which IPs sent on your domain's behalf and whether they passed. The reports are hard to read by hand, but they reveal services you forgot to authorize.

Move to strict policies step by step. Start with p=none, read the reports for a few weeks, authorize the legitimate services that fail, then move to p=quarantine and, once the reports show only your own messages passing, to p=reject. With p=reject, servers that honour DMARC refuse messages that look like they come from your domain but don't pass the checks. How to recognise such fake messages is covered in our guide to phishing and spam.

Alignment: why SPF and DKIM can pass while DMARC fails

DMARC isn't satisfied by SPF or DKIM simply passing. It requires the checked domain to be aligned with the From domain. For SPF, the Return-Path domain counts; for DKIM, the domain in the signature (the d= field). By default alignment is relaxed: bounce.yourcompany.ro matches yourcompany.ro, but newsletter-platform.com doesn't.

The typical case: a newsletter platform sends with From: news@yourcompany.ro, but signs DKIM with its own domain and uses its own Return-Path. SPF and DKIM pass, for the platform's domain, and DMARC fails. The fix is in the platform's settings, usually under "sending domain" or "domain authentication": it gives you a few CNAME or TXT records to add, after which it signs with your domain.

For subdomains, the domain's DMARC applies to them too unless they have their own _dmarc record. With the sp= tag you can ask for a different policy for subdomains, for example p=quarantine; sp=reject.

How to set them up from scratch

  1. List every service that sends email with your domain's address: the mail server, the site (forms, orders), the newsletter, the invoicing software, the CRM.
  2. Write a single SPF record that includes them all and ends with ~all or -all. Count the lookups, to stay under 10.
  3. Turn on DKIM in each service and add to DNS the key or CNAMEs each one gives you.
  4. Publish DMARC with p=none and an rua address you actually read.
  5. Send test messages from each service and check the results in the headers.
  6. After a few weeks with no legitimate messages failing, move to p=quarantine, then to p=reject.

If you add a new service later, repeat steps 2, 3 and 5 for it before it sends its first message.

How to check they pass

The simplest test: send an email to a Gmail address, open it, then choose "Show original" from the three-dot menu. The results appear at the top: SPF: PASS, DKIM: PASS, DMARC: PASS. In any other client, look for the Authentication-Results line in the message's full headers.

You can see the DNS records from a terminal:

dig TXT yourcompany.ro +short
dig TXT mail._domainkey.yourcompany.ro +short
dig TXT _dmarc.yourcompany.ro +short

On Windows, use nslookup -type=txt _dmarc.yourcompany.ro. Where these records are edited, and how to check where the nameservers point, is in our guide What is DNS.

Why emails land in spam even with SPF, DKIM and DMARC

The three records only prove who sent the message. Spam filters look at other things too:

  • The address the site sends from. A WordPress form that sends with From: customer@gmail.com is bound to fail DMARC, because your server isn't allowed to send on gmail.com's behalf. Send from an address on your domain and put the customer's address in Reply-To. The WordPress steps are in our guide to WordPress not sending email.
  • Forgotten services: the newsletter, the invoicing or the CRM send on the domain's behalf but aren't in SPF and don't sign with DKIM on your domain.
  • The IP's reputation and its reverse name (PTR). The sending server needs a valid PTR record, which Gmail requires from every sender.
  • Complaints. Google asks for the rate of messages reported as spam to stay below 0.3%. Bought lists or subscribers added without consent push the rate up quickly.
  • Sudden volume: a domain or server that hasn't sent email before and starts straight off with thousands of messages a day looks suspicious. Increase volume gradually.
  • The content: a message that's just an image, shortened links, or a subject line in capitals.

FAQ

Do I need all three?

Yes. SPF and DKIM check the sender, and DMARC ties them to the From address and gives you reports. Gmail requires DMARC from high-volume senders, and without it anyone can use your domain in fake messages.

Can I go straight to p=reject?

You can, but you risk blocking legitimate messages from services you forgot to authorize. Start with p=none and watch the reports for a few weeks.

How long before a new record takes effect?

As long as the old record's TTL, if there was one, usually under an hour. A brand-new record is usually visible within minutes. Check with dig before you send test messages.

My domain doesn't send email at all. What should I publish?

An SPF record that authorizes nothing (v=spf1 -all) and a DMARC record with p=reject. That way nobody can send convincing messages in its name.

SPF, DKIM and DMARC at AYT

On AYT hosting, the panel sets up SPF, DKIM and DMARC for your domains, and the Email Deliverability page shows the status of each record. When you add an external service that sends on your domain's behalf, you add its records in the panel's zone editor. Mailboxes on your domain, with IMAP, SMTP and webmail, are included; how to set them up on your phone and in Outlook is in our guide to domain email.

The Email Deliverability page in AYT's panel, with the status of SPF, DKIM and DMARC

More articles

All articles