How to add SPF, DKIM and DMARC records in Cloudflare
Updated · 11 min read
In short
- On Cloudflare, SPF, DKIM and DMARC are ordinary records on the DNS Records page: SPF a TXT record at @, DMARC a TXT record at _dmarc, DKIM a TXT key or CNAME records from your mail provider.
- Set every DKIM CNAME to DNS only. A proxied one answers with Cloudflare's addresses instead of your key, and DKIM fails.
- If Email Routing or another Cloudflare product already published SPF or DMARC, merge into or edit that record rather than adding a second.
On this page
- Before you start: check that Cloudflare answers for the domain
- Where the records go, and what Cloudflare calls each field
- SPF: one record at @, merged with anything Cloudflare added
- DKIM: a TXT key, or CNAMEs that must stay DNS only
- DMARC: one TXT record at _dmarc
- How to confirm it worked
- What commonly goes wrong on Cloudflare
- Sources, and how current this guide is
If your domain uses Cloudflare's nameservers, the records that decide whether your mail is trusted — SPF, DKIM and DMARC — are added on the same DNS Records page as your website's. Cloudflare's editor takes care of the fiddly parts of a text record: it adds the quotation marks a TXT value needs, and its documentation says a value longer than 255 characters is kept as several strings that receivers join back together. The two mistakes it does not stop are Cloudflare's own: putting a DKIM record behind its proxy, and adding a record next to one a Cloudflare email product has already published.
The steps below take the records in the order they depend on each other — SPF, then DKIM, then DMARC — using Cloudflare's names for each field, and end with how to prove from outside Cloudflare that each record works.
Checked against Cloudflare help, 2026-11-19. Cloudflare can rename a menu or move a button without notice, so treat the labels below as a dated snapshot: where your screen differs, look for the field each step describes. The pages we read are listed at the end, and where they say nothing, this guide says so rather than guessing.
Check yours now
Before you start: check that Cloudflare answers for the domain
A record added in the Cloudflare dashboard is only published if the domain's nameservers are the ones Cloudflare assigned when the domain was added. Where the domain is registered does not matter; where its nameservers point does, and a lookup answers that more reliably than any dashboard.
Cloudflare documents one exception itself: if a hosting partner added the domain to Cloudflare for you, Cloudflare says to manage its DNS records through that partner rather than in the dashboard.
If the lookup below returns nameservers that are not the pair Cloudflare gave you, stop here. The records belong with whoever runs those nameservers, and anything added in Cloudflare is ignored however correct it is.
dig +short NS example.comWhere the records go, and what Cloudflare calls each field
In the dashboard, select the domain and open DNS, then Records — the page Cloudflare's documentation calls the DNS Records page. Select Add record, choose a Type, fill in the fields and select Save. To change a record that already exists, select Edit on it instead of adding a second one.
- Name: a short name, not the full domain. Use @ for the domain itself, _dmarc for DMARC, and the selector followed by ._domainkey for a DKIM key. Cloudflare's own examples are written this way, and Microsoft's DKIM documentation lists Cloudflare among the hosts that add the domain to the name for you.
- The value: paste it exactly as your mail provider gives it, without quotation marks. Cloudflare's documentation says a text record saved without quotes has them added automatically, and that inconsistent quotation marks produce a validation error.
- Proxy status: shown only for A, AAAA and CNAME records, because only those can be proxied; TXT and MX records are always DNS only. It matters here for one reason, explained under DKIM below.
- TTL, which is how long other servers may keep a copy of the record: Cloudflare defines Auto as 300 seconds, so a record you correct is replaced everywhere within five minutes. Microsoft asks for more on a Microsoft 365 domain: at least an hour, 3,600 seconds, on its SPF record and its DKIM CNAMEs, and it calls 300 seconds too low for the CNAMEs, so choose one hour for those. Records that are DNS only can be set as low as 60 seconds on most plans, but there is nothing to gain from going below 300 for these.
SPF Type TXT Name @
Content: v=spf1 include:_spf.google.com ~all
DKIM Type TXT Name google._domainkey
Content: v=DKIM1; k=rsa; p=MIIBIjANBgkq...
(the whole key, from the Google Admin console)
DMARC Type TXT Name _dmarc
Content: v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com
TTL: Auto for all three. TXT records have no proxy setting.SPF: one record at @, merged with anything Cloudflare added
SPF is a single TXT record at @ that starts v=spf1 and names every service allowed to send mail as your domain. Your mail provider gives you its part: include:_spf.google.com for Google Workspace, include:spf.protection.outlook.com for Microsoft 365. Any other service that sends as you — a newsletter tool, a helpdesk, an invoicing system — goes into the same record.
Look at the record list before adding anything, because Cloudflare may already have published one. Email Routing, under Compute and then Email Service, adds v=spf1 include:_spf.mx.cloudflare.net ~all at the root along with its MX records and a DKIM key at cf2024-1._domainkey. Cloudflare's instruction for a domain that already has SPF is to merge the two into one record, for example v=spf1 include:_spf.mx.cloudflare.net include:_spf.google.com ~all.
Records that Email Routing manages are locked once it is set up: they show a Locked status, and Cloudflare's documentation says they cannot be edited or deleted from DNS Records until they are unlocked. If the SPF record you need to change is locked, unlock it first rather than working around it, because a second SPF record does not add anything: receivers that find two treat the domain as having none.
Keep the merged record under ten DNS lookups. Each include costs at least one, and Cloudflare's own merging note warns about the limit. If a merge takes you over, remove includes for services that no longer send mail before trying anything cleverer; Microsoft, for one, asks that its include never be replaced by a fixed list of addresses.
End the record with ~all while you confirm the list is complete, then move to -all once DMARC reports show nothing legitimate failing.
DKIM: a TXT key, or CNAMEs that must stay DNS only
DKIM comes in one of two shapes, and your mail provider decides which. Google Workspace gives you a TXT record named google._domainkey whose value is a key starting v=DKIM1, generated in the Admin console. Choose the 2048-bit key. Google offers 1024 bits only for hosts that cannot store a longer value, and Cloudflare is not one of them.
A 2048-bit key is longer than the 255 characters a single DNS string can hold. Cloudflare's documentation says such a value is stored as several quoted strings in one record — which is why the saved record can show a quotation mark in the middle — and that receivers join the strings back together. Paste the key as one unbroken value and let Cloudflare do the splitting.
Microsoft 365, and most sending services, give you CNAME records instead. Microsoft 365 uses two, selector1._domainkey and selector2._domainkey, pointing at targets that Microsoft shows you in its Defender portal. Copy the targets rather than building them: Microsoft changed their format for domains added from May 2025, and the old and new formats cannot be mixed for one selector.
Every DKIM CNAME must have its proxy status set to DNS only, the grey cloud. Microsoft's documentation is explicit about the alternative: lookups return Cloudflare's addresses instead of the CNAME target, and DKIM verification fails. Cloudflare says it will sometimes warn about, or refuse, proxying a CNAME used for DKIM, but do not rely on that. It also says proxying is on by default when a domain is onboarded through the dashboard, so check every CNAME that came across when the domain moved to Cloudflare.
On a paid plan, check one more setting. Cloudflare can flatten CNAME records, answering with the final destination instead of the CNAME itself, either for every CNAME in the zone from DNS Settings or record by record. Cloudflare warns that flattening a record a third party checks can make that check fail, because the CNAME is no longer returned — and Microsoft 365 looks for its two CNAMEs before it lets you switch signing on. Leave DKIM CNAMEs unflattened.
Publishing the record is half of DKIM; the provider still has to start signing. In Google Workspace, select Start authentication; Google says it can take up to 48 hours to start working. In Microsoft 365, turn on Sign messages for this domain with DKIM signatures in the Defender portal once it has found the CNAMEs.
Type CNAME Name selector1._domainkey
Target: copied from the Microsoft Defender portal
Proxy status: DNS only (grey cloud)
Type CNAME Name selector2._domainkey
Target: copied from the Microsoft Defender portal
Proxy status: DNS only (grey cloud)
TTL: one hour for both, the minimum Microsoft asks for.DMARC: one TXT record at _dmarc
DMARC is a TXT record named _dmarc. Once SPF or DKIM passes for every service that sends as you, publish v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com, with the reporting address changed to a mailbox at your own domain. Quarantine asks receivers to set failing mail aside rather than deliver it, and the rua address is where they send daily reports listing every source that sent mail as your domain.
If you do not yet know every sender, you can start with p=none for two to four weeks while the reports arrive. Be clear about what that is: p=none is a monitoring step that protects nothing, and our DMARC checker reports it as unprotected until you move on. Do not add a pct tag to stage the change. The 2026 revision of DMARC removed it, and receivers no longer agree on what it means.
Two Cloudflare products touch this record. DMARC Management, under Email and then DMARC Management, reads the reports for you: if the domain has no DMARC record it offers to add one, and if it has one it adds a Cloudflare reporting address to the rua list of the record that is already there. That changes your record rather than adding a second one, and it is harmless. Email Sending publishes v=DMARC1; p=reject; when you onboard a domain that has no DMARC record, and Cloudflare says it leaves an existing record unchanged and does not overwrite your edits.
That automatic record does two things you should know about. With p=reject, receivers are asked to refuse mail from any other service that sends as your domain and fails SPF and DKIM alignment, and the record has no rua address, so nobody receives the reports that would show which service it was. If Email Sending is the only thing sending as your domain, keep p=reject and add a rua address of your own. If other services send too, Cloudflare's advice is to drop to p=none until they pass. We suggest p=quarantine with your rua address instead while you fix them: their failing mail is set aside rather than refused, the domain stays protected, and the reports name each service still failing. Return to p=reject once the reports show nothing legitimate failing.
Whichever way the record got there, there must be only one TXT record at _dmarc, so edit the one that exists rather than adding another.
How to confirm it worked
Cloudflare says a change takes effect on its own nameservers within five minutes, usually much less. What lags is everyone else's copy: a resolver that looked up the old value keeps it until the old TTL runs out, so a record you just fixed can look broken elsewhere for a few minutes longer.
Check what is published rather than what the dashboard shows. The commands below ask DNS directly. For a DKIM CNAME, the answer should be the target hostname your provider gave you; if you get IP addresses instead, the record is proxied and needs setting to DNS only.
Then run the SPF checker, which counts every lookup the record causes; the DKIM checker with your selector, google or selector1; and the DMARC checker, which states the policy receivers will actually apply. Last, send a message to a mailbox outside your domain and read its Authentication-Results header. spf=pass, dkim=pass for your domain and dmarc=pass means the job is done, and our email header analyzer will read that header for you if you paste it in.
# exactly one line, starting v=spf1
dig +short TXT example.com | grep spf1
# Google Workspace: the key
dig +short TXT google._domainkey.example.com
# Microsoft 365: the target hostname; IP addresses mean it is proxied
dig +short selector1._domainkey.example.com
# exactly one v=DMARC1 record
dig +short TXT _dmarc.example.comWhat commonly goes wrong on Cloudflare
- A DKIM CNAME with the orange cloud on. It often saves without complaint, and every message signed with that selector then fails DKIM.
- CNAME flattening switched on for the whole zone to speed up a website, which hides the DKIM CNAMEs from the mail provider that checks for them.
- A second SPF record added next to the one Email Routing published, instead of one merged record.
- A second DMARC record added next to one that DMARC Management or Email Sending created, instead of an edit to the existing one.
- A TTL under 300 seconds left over from testing. It buys nothing for these records, and our DNS check reports it as too short outside a migration.
- A free zone close to its record limit. Cloudflare caps free zones created since September 2024 at 200 records, and the records Email Routing adds count towards it.
Sources, and how current this guide is
We read every page below on 2026-11-19 and wrote this guide from what they say, without screenshots, which go out of date faster than the text beside them.
From Cloudflare's own help:
- Create DNS records (developers.cloudflare.com)
- DNS record types (developers.cloudflare.com)
- Create zone apex record (developers.cloudflare.com)
- Proxy status (developers.cloudflare.com)
- CNAME flattening (developers.cloudflare.com)
- Set up CNAME flattening (developers.cloudflare.com)
- Time to Live (TTL) (developers.cloudflare.com)
- DNS FAQ (developers.cloudflare.com)
- Manage DNS records, including record quotas (developers.cloudflare.com)
- Email Service, domain configuration (Email Routing and Email Sending records) (developers.cloudflare.com)
- DMARC Management, enable (developers.cloudflare.com)
- DMARC Management, security records (developers.cloudflare.com)
From Google's and Microsoft's documentation, read the same day, for the steps that depend on the mail provider:
- Google Workspace Admin Help, Set up SPF (knowledge.workspace.google.com)
- Google Workspace Admin Help, Set up DKIM (knowledge.workspace.google.com)
- Microsoft Learn, Set up SPF to identify valid email sources for your Microsoft 365 domain (learn.microsoft.com)
- Microsoft Learn, How to use DKIM for email in your custom domain (learn.microsoft.com)
Check your domain with the SPF checker