Skip to content
  • There are no suggestions because the search field is empty.

Add SPF, DKIM and DMARC records in Cloudflare DNS

If your domain's DNS is on Cloudflare, that's where your SPF, DKIM and DMARC records go, but the values come from your email platform: Google Workspace, Microsoft 365, HubSpot, Mailchimp or whoever sends for you. Cloudflare just publishes them. Most failed setups come down to three Cloudflare details: a Name field that gets the domain added twice, a DKIM CNAME left on the proxy, and CNAME flattening turning a CNAME into an address. Get those right and keep one SPF and one DMARC record, and the rest is the same as any DNS host.

Where the values come from: the sending-platform guides are linked from Email sending platforms: SPF, DKIM and DMARC setup, with full guides for Mailchimp and HubSpot. Mailbox platforms are in DMARC for Microsoft 365 and DMARC for Google Workspace. What a DMARC record should say is explained in DMARC record explained: syntax, tags and examples, and the publishing steps are on our DMARC setup page. This page is only about entering the records in Cloudflare.

Where to add a record

In the Cloudflare dashboard, open your domain, go to DNS, then Records, and choose Add record. Pick the Type, fill in the fields and save. You edit or delete existing records from the same table.

The fields change with the type. A, AAAA and CNAME records also show Proxy status and TTL. Comments and tags are optional.

Use relative names, then check the full name

The Name field takes the host relative to your domain, or @ for the domain itself (the apex). For example.com:

Record Type Name to enter Full name to check afterwards
SPF TXT @ example.com
DMARC TXT _dmarc _dmarc.example.com
DKIM CNAME or TXT selector._domainkey (your platform's selector) selector._domainkey.example.com

Cloudflare adds your domain to the name you enter. So if a platform shows a full name, such as k2._domainkey.example.com, enter only k2._domainkey. Then read the saved name in the records table. You want _dmarc.example.com, not _dmarc.example.com.example.com. Entering the relative name and then checking the result is the safe habit.

DKIM CNAMEs must be DNS-only

Only A, AAAA and CNAME records can be proxied, shown by the orange cloud. TXT and MX records are always DNS-only.

A proxied CNAME answers with Cloudflare's addresses instead of pointing to your email platform's target. The platform can't verify your domain, and receivers can't find your DKIM key. So set every DKIM CNAME, and any other CNAME your email platform asks for, to DNS-only (the gray cloud).

The same goes for any mail hostname: anything used for SMTP, IMAP or POP, and anything an MX record points to, has to be DNS-only too.

Turn CNAME flattening off for those records

CNAME flattening makes Cloudflare answer with the final IP address instead of the CNAME. Email platforms that verify a domain through a CNAME, which is usual for DKIM, need to see the CNAME itself. Flattened, the lookup fails.

  • In your zone's DNS settings, turn off the option to flatten all CNAME records when you're publishing DKIM or verification CNAMEs. HubSpot, for one, needs domain-wide CNAME flattening turned off.
  • On each of those CNAME records, turn off the per-record Flatten option as well, and keep the proxy status at DNS-only.
  • If you don't see the zone-wide flattening option on your plan, you still need each DKIM CNAME set to DNS-only.

Flattening at the apex is a separate, default behaviour. DKIM names never sit at the apex, so it doesn't affect them.

Adding the SPF record

  • Type: TXT.
  • Name: @ for the apex, or the sending subdomain if SPF belongs there. A subdomain doesn't inherit the parent's SPF record, the way it can inherit a DMARC policy (Shared domains and multi-service setups).
  • Content: the record your platforms need, for example v=spf1 include:_spf.google.com ~all.

There can only be one SPF record per name. If one exists, edit it and add the new include. Don't add a second TXT starting with v=spf1 (Two SPF records). Each include costs DNS lookups, and SPF allows 10 (The 10-lookup limit and SPF permerror).

Cloudflare SPF record not working?

Proxy settings aren't the cause, because TXT records are always DNS-only. Check these instead:

  • A doubled name, such as example.com.example.com, so the record isn't at the name receivers look up.
  • Two SPF records at the same name, often one old and one new.
  • A wrong or mistyped include, or one that takes the record past 10 lookups.

Adding the DMARC record in Cloudflare

  • Type: TXT.
  • Name: _dmarc, then check that the full name reads _dmarc.example.com.
  • Content: your policy. If you're starting out, monitor first:
v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com

Put the reporting address our platform gives you in rua, in place of the example. That's where your aggregate reports arrive, and in our reporting each sending source then gets its own view with visual analysis.

There can only be one DMARC record per name. If one exists, edit it. Receivers ignore a domain's DMARC records when there's more than one. If a sending platform's setup offers a sample DMARC record, don't let it overwrite your enforcement policy or replace your rua.

Tag meanings are in DMARC tags explained: p, sp, np, adkim, aspf, rua, ruf, fo, and t, report addresses and authorization in rua, ruf, and report authorization, and moving from p=none toward enforcement in A safe rollout: p=none to quarantine to reject. Subdomain policy is in Subdomain policy (sp).

Adding DKIM records

Your platform tells you whether DKIM is a CNAME (common for sending platforms and Microsoft 365) or a TXT holding a public key (as with Google Workspace).

  • CNAME: enter the relative name, paste the target exactly, set DNS-only, and turn flattening off.
  • TXT: enter the relative name and paste the full key value exactly as the platform shows it.

Publishing the record doesn't switch signing on. Go back to the platform and finish its own authentication or enable-signing step.

Check the records

First, read the records table. For each one, check the Type, the full Name, the Content and, for CNAMEs, DNS-only with Flatten off.

Then ask DNS directly. With dig:

dig +short TXT example.com
dig +short TXT _dmarc.example.com
dig +short CNAME selector._domainkey.example.com

You want exactly one TXT starting with v=spf1 at the SPF name and exactly one TXT starting with v=DMARC1 at _dmarc. Each DKIM CNAME should come back as your platform's target name, not as an IP address. nslookup -type=TXT _dmarc.example.com does the same job on Windows.

Then go back to the platform and check its own status, and send a real test message (How to add a third-party sender without breaking DMARC). DNS changes often show up within minutes and can take up to 48 hours.

A BIMI record goes here too, later

When your domain is at enforcement and you're ready for BIMI, its record is another TXT at default._bimi, entered with the same Name-field care. TXT records are always DNS-only, so there's no proxy setting to worry about. What BIMI needs, and why DMARC comes first, is in What is BIMI, and why DMARC comes first and How to move from DMARC enforcement to BIMI.

Free DMARC account

Turn raw DMARC reports into a readable dashboard

Point your rua address to our platform and read the results by sender and source instead of opening XML files.

  • Results grouped by sending source
  • SPF, DKIM and alignment results per sender
  • The original XML reports are still there to download

Create a free DMARC accountTalk to an expert

FAQ

Should DKIM CNAMEs be proxied in Cloudflare?

No. Set them to DNS-only, and turn CNAME flattening off if your email platform needs to see the CNAME.

I entered _dmarc.example.com and the record looks wrong. Why?

The name has probably picked up your domain twice. Enter _dmarc only, then confirm the records table shows _dmarc.example.com.

Where do I put the DMARC report address?

In the rua tag of your one DMARC record, using the reporting address our platform gives you. If a record already exists, edit it rather than adding another.

HubSpot or Mailchimp still won't verify the domain. What should I check?

DNS-only on the CNAMEs, flattening off, a Name field that isn't doubled, and enough time for DNS, often minutes and sometimes up to 48 hours. Then follow that platform's own status check in its guide.