Skip to content

DKIM records on Cloudflare: long TXT values, quoting, and provider examples

A 2048-bit DKIM key does not fit in one 255-byte TXT string, and pasted quotes corrupt the value. How Cloudflare handles long DKIM records, and the exact records Google, Microsoft 365, and SendGrid expect.

A DKIM record is a TXT (or CNAME) at selector._domainkey.example.com carrying the public key receivers use to verify your mail’s signature. On Cloudflare the good news is that the dashboard does the hard part for you: paste the full key — even a 2048-bit one that exceeds the DNS 255-byte string limit — into the content field with no quotation marks, and Cloudflare splits it into multiple strings automatically. Nearly every broken DKIM record we see was damaged on the way in: pasted quotes kept as literal characters, line breaks from an email client’s wrapping, or a truncated p= value. The other Cloudflare-specific rule: when a provider gives you DKIM as a CNAME, that CNAME must stay DNS-only.

What’s happening

DNS TXT records are stored as one or more character-strings of at most 255 bytes each; resolvers concatenate the strings back into one value. A 1024-bit RSA key fits in one string, a 2048-bit key does not — its record must be split. Where BIND makes you split it by hand into quoted segments, Cloudflare’s dashboard and API accept the full value and handle segmentation internally, and serve the strings so that verifiers reassemble the exact key. The failure modes are therefore about the value you paste, not the splitting: a stray " becomes part of the key material, a space or newline inside the base64 breaks it, and both produce dkim=fail or dkim=permerror with a record that “looks right” in the dashboard.

The second mechanism is CNAME-based DKIM, used by Microsoft 365, SendGrid, Amazon SES, and others: you publish a CNAME at the selector name and the provider hosts the actual TXT at the target, which lets them rotate keys without touching your zone. A proxied CNAME breaks this completely — the orange cloud makes Cloudflare answer address queries with edge IPs and hide the CNAME target, so a verifier’s TXT query at your selector name returns nothing. Selector names contain _domainkey, and Cloudflare generally keeps underscore names unproxied, but check the grey cloud anyway whenever the record was created by import or API.

What to check first

  • What form your provider uses. Google Workspace hands you a TXT value; Microsoft 365 and SendGrid hand you CNAMEs; Amazon SES hands you three CNAMEs.
  • The selector name. It goes in Cloudflare’s Name field as selector._domainkey — Cloudflare appends the zone itself. Typing the full FQDN can produce selector._domainkey.example.com.example.com.
  • The pasted value. No surrounding quotes, no line breaks, ends in the full key (often IDAQAB), semicolon-separated tags intact (v=DKIM1; k=rsa; p=...).
  • Proxy status on CNAME selectors. Grey cloud, always.

How to verify

# The assembled record as receivers see it
dig +short TXT google._domainkey.example.com
dig @1.1.1.1 +short TXT selector1._domainkey.example.com

# For CNAME-based DKIM, confirm the chain is visible
dig +short CNAME s1._domainkey.example.com
dig +short TXT s1._domainkey.example.com

Multiple quoted strings in the answer are normal; verifiers join them. What matters is that the concatenation is one clean v=DKIM1...p=... value. Then prove a signed message passes:

# Send a test through the real signing path
swaks --to you@your-test-mailbox.net --from app@example.com --server 127.0.0.1

# At the destination, read the verdict:
# Authentication-Results: ...; dkim=pass header.d=example.com header.s=selector1

# On your own MTA, watch signing happen
grep -i dkim /var/log/exim_mainlog | tail -20

The fix

  1. Take the value straight from the provider’s screen, not from an email that may have wrapped it. If the provider offers a copy button, use it.

  2. Create the record in Cloudflare: Type TXT, Name selector._domainkey, Content the full value with no quotes, TTL Auto. For long keys, save and re-open the record — Cloudflare shows the stored value; it should match end to end.

  3. For CNAME-based providers, create each CNAME exactly as issued and leave it DNS-only:

    # Microsoft 365 — two CNAMEs, DNS-only
    selector1._domainkey  CNAME  selector1-example-com._domainkey.contoso.onmicrosoft.com
    selector2._domainkey  CNAME  selector2-example-com._domainkey.contoso.onmicrosoft.com
    
    # SendGrid — from Settings, Sender Authentication
    s1._domainkey  CNAME  s1.domainkey.u1234567.wl123.sendgrid.net
    s2._domainkey  CNAME  s2.domainkey.u1234567.wl123.sendgrid.net
    
    # Google Workspace — a TXT you paste yourself
    google._domainkey  TXT  v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...IDAQAB
  4. Trigger the provider’s verification step (Microsoft 365 admin center, SendGrid’s Verify button, Google’s “Start authentication”) only after dig @1.1.1.1 returns the record — provider checks that run before propagation fail and some back off for hours.

  5. Send one signed test message per selector and confirm dkim=pass with the right header.s= at the destination.

When this fix is wrong

If DNS serves the key cleanly but mail still shows dkim=fail, the problem is on the signing side: the MTA signs with a different selector than the one published, the key pair was regenerated after you copied the record, or an intermediary rewrote the message body. Verify the selector named in the DKIM-Signature header matches what you published before touching DNS again. Mailing lists and some forwarders alter content and break body hashes — that is a DMARC/ARC conversation, not a record error.

Common mistakes

  • Pasting BIND-style quoted segments ("v=DKIM1; k=rsa; p=MIIB..." "...IDAQAB") so the quotes and the gap become part of the value.
  • Splitting a long key by hand and adding a space at the join.
  • Entering the full FQDN in the Name field and doubling the zone.
  • Orange-clouding a provider’s DKIM CNAME, making the TXT lookup return nothing.
  • Deleting the old selector the moment a new one verifies — mail signed minutes earlier still needs the old key published. Rotate by adding, then retiring later.

Prevention

Keep DKIM changes boring: copy from the provider, paste raw, verify with dig from a neutral resolver, and only then run provider verification. Cloudflare’s DNS documentation covers TXT record handling; for the wire-format details behind the 255-byte segmentation, see how DKIM TXT values are segmented, and for the full mail-record layout, the DNS record cookbook.

Mail that breaks after a DNS move is one of the most common incidents we untangle — Stack Harbor manages the full DNS and mail path under Managed Cloud Ops; book an infrastructure review before the next migration.