How do you add SPF, DKIM and DMARC records in Cloudflare?
In Cloudflare, open your domain's DNS Records page, select Add record, choose the type (TXT for SPF and DMARC, TXT or CNAME for DKIM, MX for mail routing), enter the name and value your provider gives you, and save. Keep every mail-related A, AAAA and CNAME record on DNS only, never proxied.
On this page 10 sections
Cloudflare makes adding DNS records quick, but one setting trips up email setups again and again: the orange proxy cloud. Email authentication records only work when receivers can read them exactly as your provider intended, and mail servers only work when their hostnames point to real IP addresses, not Cloudflare's web proxy.
This guide walks through adding SPF, DKIM, DMARC and MX records in the Cloudflare dashboard, with the rules for each field. If you're not sure what each record does yet, start with SPF vs DKIM vs DMARC.
Where do you add DNS records in Cloudflare?
Your domain must use Cloudflare's nameservers for these records to matter. If your registrar still points the domain at other nameservers, records you add in Cloudflare won't be seen by anyone. Our MX Lookup shows which nameservers are live for your domain.
Cloudflare's own steps for any record are short (Cloudflare Docs):
- Sign in to the Cloudflare dashboard and select your domain.
- Open the DNS > Records page.
- Select Add record.
- Choose a record Type.
- Fill in the fields for that type.
- Select Save.
The fields you'll see:
| Field | What to enter |
|---|---|
| Type | TXT, CNAME or MX, depending on the record |
| Name | @ for your bare domain, or just the prefix (such as _dmarc) for anything else |
| Content (or Mail server for MX) | The value your email provider gives you |
| Proxy status | Only shown for A, AAAA and CNAME. Set mail-related records to DNS only |
| TTL | Auto is fine. Cloudflare says Auto "is set to 300 seconds (five minutes)" (Cloudflare Docs) |
| Priority | MX records only. Lower numbers are tried first |
Cloudflare documents @ as the way to create a record at the zone apex (Cloudflare Docs). For other names, type only the part before your domain. If your provider tells you to create _dmarc.example.com, enter _dmarc.
Why must email records be DNS only in Cloudflare?
Cloudflare's proxy is built for web traffic. Its documentation is direct about the limits: only A, AAAA and CNAME records can be proxied, and "Other record types (such as MX or TXT) are always DNS-only" (Cloudflare Docs). So your SPF, DMARC and MX records can't be proxied by mistake.
The risk sits in the records mail depends on that can be proxied:
- The host your MX points to. If
mail.example.comis a proxied A record, it resolves to a Cloudflare IP address. Cloudflare's troubleshooting guide says "Mail protocols such as SMTP, IMAP, and POP3 do not work through Cloudflare's standard HTTP proxy," and that "YourMXrecord itself is always DNS-only, but the hostname it points to must also resolve to a DNS-only target" (Cloudflare Docs). - DKIM CNAME records. Some providers, including Microsoft 365, publish DKIM keys through CNAME records. These must reach the provider's real record. Cloudflare says it may prevent proxying for CNAMEs "used for DKIM (email authentication) validation," and that records used to prove domain ownership "should not be proxied" (Cloudflare Docs).
- Autodiscover and other mail service CNAMEs. Cloudflare lists these among the hostnames to check when mail breaks.
The rule is simple: if a record exists for email, its proxy status should show DNS only (a grey cloud).
What about CNAME flattening?
Cloudflare's troubleshooting guide warns that with CNAME flattening on, a CNAME "is flattened to an A record, which can prevent email providers from reading the record correctly." If your DKIM CNAMEs don't resolve as the provider expects, Cloudflare says you may need to turn CNAME flattening off for them (Cloudflare Docs).
How do you add an SPF record in Cloudflare?
SPF is a TXT record on your bare domain. A domain must have only one SPF record: RFC 7208, section 3.2 says a domain "MUST NOT have multiple records" that a check would select. So look before you add.
- On the DNS > Records page, search the list for a TXT record on your bare domain that starts with
v=spf1. - If one exists, select Edit and merge your new provider into it, rather than adding a second record.
- If none exists, select Add record, choose TXT, enter
@as the Name, and paste the SPF value as the Content, for examplev=spf1 include:_spf.google.com ~all. - Select Save.
Not sure what your record should contain? Our SPF Record Generator builds one from your list of senders and counts DNS lookups, and our SPF provider pages list the exact include for each mail service. The SPF syntax guide explains each part.
How do you add a DKIM record in Cloudflare?
Your email provider generates the DKIM key, so you copy what it gives you. It will be one of two shapes.
DKIM as a TXT record
Google Workspace and many other services give you a TXT record.
- Select Add record and choose TXT.
- For Name, enter the selector name followed by
._domainkey, for examplegoogle._domainkey. - Paste the full key value, starting
v=DKIM1;, into Content. - Select Save.
DKIM as a CNAME record
Microsoft 365 and several sending platforms give you CNAME records that point to a key they host.
- Select Add record and choose CNAME.
- For Name, enter the host they give you, such as
selector1._domainkey. - For Target, paste the provider's value.
- Set Proxy status to DNS only.
- Select Save, then repeat for the second selector if there is one.
Our DKIM setup guide for Microsoft 365 and Google Workspace covers where to find these values in each admin console, and our DKIM records by provider pages list the selector names each service uses.
How do TXT quotes and long DKIM keys work in Cloudflare?
DNS stores TXT content as one or more quoted strings. Cloudflare explains that inconsistent quotation marks can cause a validation error, and that "if you save your TXT content without any quotes, Cloudflare will automatically add double quotes" (Cloudflare Docs).
In practice:
- Paste the value without adding your own quotes. Cloudflare adds them.
- If your provider shows the key as several quoted chunks, that's normal for long 2048-bit keys. Receivers join the strings back together. RFC 6376, section 3.6.2.2 says DKIM strings "MUST be concatenated together before use with no intervening whitespace," and RFC 7208, section 3.3 says the same for SPF.
- Watch for stray spaces or line breaks when copying a key from a PDF or email. A single extra character breaks the signature check.
How do you add a DMARC record in Cloudflare?
DMARC is a TXT record at _dmarc on your domain.
- Select Add record and choose TXT.
- Enter
_dmarcas the Name. - Enter your policy as the Content. A safe first record is
v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com, using a mailbox you actually read. - Select Save.
There must be only one DMARC record at that name. Start at p=none, read the reports, and move toward enforcement once every legitimate sender passes. Our DMARC Record Generator builds the record, DMARC record examples explains each tag, and the path from none to reject covers the rollout.
How do you add MX records in Cloudflare?
MX records tell other servers where to deliver your mail. Cloudflare's example uses Type MX, Name @, a Mail server hostname and a Priority (Cloudflare Docs).
- Select Add record and choose MX.
- Enter
@as the Name. - Enter the hostname your provider or filtering service gives you as the Mail server. It must be a hostname, not an IP address.
- Enter the Priority they specify.
- Select Save, and repeat for any additional MX hosts.
- Remove MX records for your old provider only when your plan says to.
If you run your own mail server, Cloudflare's guide adds an A record for the mail subdomain, such as mail, set to DNS only, and points the MX record at it. Changing MX records moves where your mail goes, so read how to change MX records without losing email before you touch them.
How do you check your records after saving?
Cloudflare suggests checking MX resolution with dig example.com mx +short (Cloudflare Docs). The same command works for the other records:
dig example.com mx +short
dig example.com txt +short
dig _dmarc.example.com txt +short
dig selector1._domainkey.example.com cname +short
If a hostname used for mail returns a Cloudflare IP address, it's proxied and needs switching to DNS only. If you see a _dc-mx name in your MX results, an MX record is pointing at a proxied host.
Without a terminal, use our tools:
| Check | Tool |
|---|---|
| MX hosts and backup MX | MX Lookup |
| One SPF record, lookup count, syntax | SPF Checker |
| DKIM key by selector | DKIM Checker |
| DMARC policy and reporting | DMARC Checker |
Remember that a resolver that cached an old answer keeps it until the TTL expires. If a check still shows the old value, wait for the previous TTL and try again.
What are the common Cloudflare email record mistakes?
- A second SPF record added for a new service instead of editing the first. This causes an SPF PermError.
- A record on the wrong name. DMARC belongs at
_dmarc, DKIM at<selector>._domainkey, and SPF at@. After saving, check the full name shown in the records list. - A proxied mail hostname or DKIM CNAME. Switch it to DNS only.
- Quotes added by hand with one missing, which Cloudflare rejects or stores incorrectly.
- Records added in Cloudflare while the registrar points elsewhere. Check the live nameservers first.
Next steps
- Run the Email Health Check to see your MX, SPF, DKIM and DMARC records in one scan.
- Build or fix your SPF with the SPF Record Generator and your DMARC with the DMARC Record Generator.
- Confirm your DKIM key with the DKIM Checker.
- Setting up a brand-new domain? Follow the new domain email setup checklist.
If you're pointing MX at a filtering service such as iBlockSpam, the same Cloudflare steps apply: MX records are always DNS only. See all SPF, DKIM and DMARC guides.
Frequently asked questions
Should email DNS records be proxied in Cloudflare?
No. MX and TXT records can't be proxied at all; Cloudflare says they are always DNS-only. Any A, AAAA or CNAME record that mail depends on, such as the host your MX points to or a DKIM CNAME, should be set to DNS only. Mail protocols don't work through Cloudflare's HTTP proxy.
Do I need quotation marks around TXT records in Cloudflare?
No. Cloudflare says that if you save new TXT content without quotes, it adds the double quotes for you. Problems come from inconsistent quotes, such as one quote at the start and none at the end, which can cause a validation error. Paste the value exactly as your provider gives it, without adding your own quotes.
What does the @ mean in the Cloudflare Name field?
The @ symbol means the zone apex, your bare domain such as example.com. Use @ for your SPF record and your MX records. For DMARC enter _dmarc, and for DKIM enter the selector name your provider gives you, such as selector1._domainkey, without your domain on the end.
How long do Cloudflare DNS changes take to work?
Cloudflare serves new records from its nameservers quickly, but resolvers that cached the old answer keep it until its TTL runs out. Cloudflare's Auto TTL is 300 seconds. If you're replacing a record that had a long TTL elsewhere, allow for that older TTL before you judge whether the change worked.
Why does a _dc-mx record appear in my Cloudflare MX results?
Cloudflare documents that when an MX record points at a proxied hostname, it inserts a _dc-mx name into DNS answers that resolves to the origin IP, so mail bypasses the proxy (dc- names are the SRV equivalent). The clean fix is a separate DNS-only hostname for mail, such as mail.example.com, with the MX record pointing to it while your website hostname stays proxied.
Sources
- Cloudflare Docs: Create DNS records
- Cloudflare Docs: Proxy status
- Cloudflare Docs: DNS record types (TXT)
- Cloudflare Docs: Set up email records
- Cloudflare Docs: Troubleshooting email issues
- Cloudflare Docs: Time to Live (TTL)
- RFC 7208: Sender Policy Framework (SPF), sections 3.2 and 3.3
- RFC 6376: DomainKeys Identified Mail (DKIM), section 3.6.2.2
See how your domain measures up
Run a free Email Health Check: MX, SPF, DKIM, DMARC and transport security in one scan, with the raw records shown. No sign-up.
Keep reading
How do you set up email on a new business domain?
Setting up email on a new business domain? Follow this checklist: MX, SPF, DKIM, DMARC from p=none to enforcement, optional MTA-STS and BIMI, PTR and warm-up.
10 min read Setup guidesHow do you add email DNS records in GoDaddy?
How to add and edit SPF, DKIM, DMARC and MX records in GoDaddy DNS: exact fields, the one-SPF-record rule, Domain Protection checks and how to verify them.
8 min read Setup guidesHow do you add email DNS records in Namecheap?
How to add SPF, DKIM and DMARC TXT records and custom MX records in Namecheap Advanced DNS, what goes in the Host field, and how to check that they work.
8 min read