---
title: "SPF, DKIM and DMARC explained for developers | sendmcp"
url: https://sendmcp.dev/blog/spf-dkim-dmarc-explained/
description: "SPF, DKIM and DMARC are 3 DNS TXT records. What each proves, how alignment works, a none to reject DMARC rollout, 3 common mistakes and dig checks."
---

[Blog](https://sendmcp.dev/blog/)

# SPF, DKIM and DMARC for developers, set up on Cloudflare

SPF, DKIM and DMARC are **3 DNS TXT records**. SPF lists the servers allowed to send for a domain. DKIM publishes the key that checks each message's signature. DMARC passes a message when SPF or DKIM passes and its domain matches the From address. Roll DMARC out in 3 steps: `none`, `quarantine`, then `reject`.

By [itsnex1s](https://x.com/itsnex1s) · Published Nov 23, 2026 · Updated Nov 23, 2026

## What do SPF, DKIM and DMARC each do?

All three are published as TXT records in your DNS zone. Receiving servers look them up on every message. The example values below use `example.com` and the record names Cloudflare Email Sending uses.

| Record | DNS type | Name | Example value | What it proves |
| --- | --- | --- | --- | --- |
| SPF | TXT | `cf-bounce.example.com` | `v=spf1 include:_spf.mx.cloudflare.net ~all` | The server that connected is allowed to send for the envelope sender's domain |
| DKIM | TXT | `cf-bounce._domainkey.example.com` | `v=DKIM1; h=sha256; k=rsa; p=MIIB...` | The message carries a valid signature from a key the domain published, and the signed parts were not changed |
| DMARC | TXT | `_dmarc.example.com` | `v=DMARC1; p=none; rua=mailto:dmarc@example.com` | SPF or DKIM passed for a domain that matches the From address, plus your policy and where reports go |

SPF is defined in [RFC 7208](https://www.rfc-editor.org/rfc/rfc7208.html), DKIM in [RFC 6376](https://www.rfc-editor.org/rfc/rfc6376.html) and DMARC in [RFC 7489](https://www.rfc-editor.org/rfc/rfc7489.html). SPF records must be TXT records. The dedicated SPF record type was discontinued.

The SPF qualifier on `all` sets how strict the record is. `-all` means fail, `~all` means softfail, a weak statement that the host is probably not authorized. RFC 7208 advises receivers not to reject on softfail alone.

Each DKIM signature names a signing domain in `d=` and a selector in `s=`. The selector lets one domain publish several keys. The public key lives in a TXT record at `selector._domainkey.domain`. Only one TXT record may exist per selector. DKIM requires the From header to be signed.

## What is alignment, and why does DMARC need it?

SPF and DKIM on their own prove a domain, but not necessarily the one the reader sees. A spammer can pass SPF for their own domain and still put your domain in the From address. DMARC closes that gap. It passes a message only when SPF or DKIM passes *and* the authenticated domain is aligned with the From domain.

| Mode | Tag | Rule | Example that passes |
| --- | --- | --- | --- |
| Relaxed (default) | `adkim=r`, `aspf=r` | Both domains share the same organizational domain | From `example.com`, SPF checked on `cf-bounce.example.com` |
| Strict | `adkim=s`, `aspf=s` | The domains match exactly | From `example.com`, DKIM `d=example.com` |

One aligned pass is enough. DMARC does not need both SPF and DKIM to align. That is why a sending service can authenticate with its own bounce subdomain and still pass your DMARC check under relaxed alignment. The organizational domain is found with the public suffix list, so it is a heuristic (RFC 7489, section 3.2).

## How do I roll out DMARC without losing mail?

The `p` tag sets the policy. Move up one step at a time, and read the aggregate reports between steps.

| Step | Record | What receivers do | Move on when |
| --- | --- | --- | --- |
| 1. Monitor | `v=DMARC1; p=none; rua=mailto:dmarc@example.com` | Nothing to failing mail. You get reports | Reports show every real sender passing with an aligned SPF or DKIM |
| 2. Quarantine | `v=DMARC1; p=quarantine; pct=10; rua=mailto:dmarc@example.com` | Send failing mail to spam, for `pct` percent of messages | No legitimate mail lands in spam. Raise `pct` to 100 |
| 3. Reject | `v=DMARC1; p=reject; rua=mailto:dmarc@example.com` | Refuse failing mail | Stay here, and keep reading reports |

Details that matter:

- `pct` is a number from 0 to 100 and defaults to 100. Reports are never sampled. Google recommends starting with a small percentage and raising it to 100.
- Google recommends enabling SPF or DKIM first and waiting 48 hours before you add DMARC.
- `rua` reports can be high volume. Send them to a dedicated mailbox, a group or a reporting service, not to your own inbox.
- If the `rua` address is on a different domain, that domain must publish a TXT record containing `v=DMARC1` at `<your-domain>._report._dmarc.<report-host>`. Without it, receivers ignore the address (RFC 7489, section 7.1).
- `sp` sets a separate policy for subdomains. Without it, `p` applies to them too.

Check what is already in your zone before you start. Cloudflare adds `v=DMARC1; p=reject;` when you onboard a sending domain, but only if no DMARC record exists. If other systems send mail as your domain, switch that record to `p=none` first. Gmail and Yahoo require a DMARC record from bulk senders, and `p=none` satisfies them: see [the sender requirements checklist](https://sendmcp.dev/blog/gmail-yahoo-sender-requirements/).

## What mistakes break the records?

| Mistake | What happens | Fix |
| --- | --- | --- |
| Two SPF records on one name | SPF returns `permerror` and fails for every message (RFC 7208, section 4.5) | Merge them into one record with several `include:` terms |
| More than 10 DNS lookups in SPF | SPF returns `permerror`. Terms that count: `include`, `a`, `mx`, `ptr`, `exists` and `redirect`. `ip4`, `ip6` and `all` do not count | Drop services you no longer use, or replace `include:` terms with `ip4:` ranges. More than 2 lookups that return nothing also trigger `permerror` |
| Wrong DKIM selector | Receivers query `s=` and `d=` from the signature. A key published under a different name is never found | Copy the name the sender shows. Read `s=` and `d=` from a real message header and query that exact name |
| Two DMARC records | Receivers drop DMARC for the message (RFC 7489, section 6.6.3) | Keep one TXT record on `_dmarc` |
| Jumping straight to `p=reject` | Legitimate mail from a forgotten system is refused | Run `p=none` with `rua` first |
| Pasting a long DKIM key as one string | A TXT string is limited to 255 octets | Split it into several quoted strings. Receivers join them with no spaces |

If a domain already has an SPF record, merge the new entries into it. Cloudflare says the same in its domain setup page.

## How do I check the records with dig?

Query each name and read the TXT answer. Add `+short` for the value only.

 `# SPF: the envelope sender domain dig TXT cf-bounce.example.com +short "v=spf1 include:_spf.mx.cloudflare.net ~all" # DKIM: selector + _domainkey + signing domain dig TXT cf-bounce._domainkey.example.com +short "v=DKIM1; h=sha256; k=rsa; p=MIIB..." # DMARC dig TXT _dmarc.example.com +short "v=DMARC1; p=none; rua=mailto:dmarc@example.com"`

Count the answers. Two lines starting with `v=spf1` or `v=DMARC1` are a bug. To find the right DKIM name, open a delivered message and look at its `DKIM-Signature` header:

 `DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=selector1;... # the key is at s +._domainkey. + d dig TXT selector1._domainkey.example.com +short`

To ask a specific resolver, put it after an at sign: `dig @1.1.1.1 TXT _dmarc.example.com +short`. Cloudflare says a new record that shows "Not Found" usually needs 5 to 15 minutes, and propagation can take up to 24 hours.

## How do I set this up on Cloudflare?

Cloudflare Email Sending, a public beta, manages the sending records for each domain you onboard. If you work through an agent, [sendmcp](https://sendmcp.dev/) is a free, MIT-licensed Worker on your own Cloudflare account whose MCP tools write the records (`domains_add`) and read back the DMARC policy (`deliverability_check`). It follows the rule above: it leaves an existing DMARC record alone, writes `p=none` with reports when other services send as the domain, and keeps Cloudflare's `p=reject` when nothing else does. The steps are on [the SPF, DKIM and DMARC setup page](https://sendmcp.dev/spf-dkim-dmarc-cloudflare/).

## Sources

1. [RFC 7208: Sender Policy Framework (SPF)](https://www.rfc-editor.org/rfc/rfc7208.html) checked Nov 23, 2026
2. [RFC 6376: DomainKeys Identified Mail (DKIM) Signatures](https://www.rfc-editor.org/rfc/rfc6376.html) checked Nov 23, 2026
3. [RFC 7489: DMARC](https://www.rfc-editor.org/rfc/rfc7489.html) checked Nov 23, 2026
4. [Cloudflare: Email Service, domain configuration](https://developers.cloudflare.com/email-service/configuration/domains/) checked Nov 23, 2026
5. [Cloudflare: DNS record types](https://developers.cloudflare.com/dns/manage-dns-records/reference/dns-record-types/) checked Nov 23, 2026
6. [Google: Set up DMARC](https://knowledge.workspace.google.com/admin/security/set-up-dmarc) checked Nov 23, 2026

## Questions about this

### Do I need both SPF and DKIM for DMARC to pass?

No. DMARC passes when either SPF or DKIM passes for a domain that aligns with the From address. Set up both anyway: Gmail and Yahoo require both from bulk senders.

### Can a domain have two SPF records?

No. Two SPF records on the same name make SPF return `permerror`. Put every sending service in one record, and keep it under 10 DNS lookups.

### Is p=none enough?

It is enough to meet the Gmail and Yahoo bulk sender rules, which ask for a DMARC record with at least `p=none`. It does not stop anyone from spoofing your domain. Move to `quarantine` and then `reject` when the reports are clean.

## Related questions

### How do I set up SPF, DKIM and DMARC on Cloudflare?

Your agent writes all three records to your zone and checks alignment on a test send.

[How do I set up SPF, DKIM and DMARC on Cloudflare?](https://sendmcp.dev/spf-dkim-dmarc-cloudflare/)

### Gmail and Yahoo sender requirements in 2026

The checklist for all senders and for bulk senders, with dates.

[Gmail and Yahoo sender requirements in 2026](https://sendmcp.dev/blog/gmail-yahoo-sender-requirements/)

### Why did my email bounce, and how do I fix it?

bounce_explain reads the SMTP response and names the cause and the fix.

[Why did my email bounce, and how do I fix it?](https://sendmcp.dev/why-did-my-email-bounce/)

## Send from every project for $0.

Open source. One click puts it on your Cloudflare account.

[Deploy to Cloudflare](https://deploy.workers.cloudflare.com/?url=https://github.com/agentfirsthq/sendmcp)
