Deliverability

Your DKIM signature is not valid (mail-tester): causes and fixes

Mail-tester shows "Your DKIM signature is not valid" when the signature in your test message fails verification against the public key in DNS. Read the raw headers first: compare the selector and d= domain with your published record, then check for quotes, Cloudflare proxying, altered headers and stale DNS.

Sohail HussainSohail Hussain11 min read

Short answer

  • Open the raw headers of the exact message you sent to mail-tester, read the s= and d= values in the DKIM-Signature header, and confirm a TXT or CNAME record exists at {s}._domainkey.{d} with an unbroken key.
  • If you use Cloudflare with CNAME-based DKIM (Microsoft 365, for example), set the record to DNS only. Then send a brand-new message, because old test reports prove nothing.
  • If the key is found but verification still fails, something changed the message after signing, or d= does not match your From domain.

You ran a test and mail-tester gave you this:

Your DKIM signature is not valid.

Yet the record in your DNS panel looks right. The record is often fine. The problem is usually a mismatch between what the message says and what DNS says, a mangled value, or a message that changed after it was signed.

Why mail-tester says the DKIM signature is not valid

Mail-tester received your message, found a DKIM-Signature header, and could not verify it. It reports the result, not the reason. Verification has three steps: read s= (selector) and d= (domain) from the header, fetch the public key at {s}._domainkey.{d}, and check the signature against the key and the message. A failure at any step produces the same label.

Causes, roughly most common first:

  1. Selector or host mismatch. The header says one selector, and the record sits under another, or under a doubled domain name.
  2. A mangled TXT value. Literal quote characters, stray spaces or line breaks inside p=, or a long key that was cut off.
  3. Cloudflare proxying a CNAME-based DKIM record. Microsoft's documentation says a proxied record returns Cloudflare's IP addresses instead of the CNAME target, and DKIM verification fails.
  4. Stale test. The key was published or generated after the message was sent, or DNS had not propagated.
  5. The message changed after signing. Disclaimers, banners, link rewriting or a relay downstream of the signer.
  6. A weird selector name. Underscores in the selector itself, which some validators reject.
  7. Wrong signing domain. Mail signed with onmicrosoft.com or your provider's domain while the From address is yours. Strictly this is an alignment problem for DMARC, but some checkers blur the two.

People on vendor community forums and in self-hosted mail threads (Cloudflare, Stalwart and Mailcow users, for example) report the same label with several of these causes. The message text alone never tells you which one you have.

Step-by-step fixes

Fix 1: read the headers and query the exact DNS name

  1. Send a new message from the sending account to your mail-tester address, and also to a mailbox you control.
  2. In the mailbox you control, open the original message source. In Gmail, that is Show original.
  3. Find the DKIM-Signature header and note s= and d=.
  4. Find the Authentication-Results header, if present, and note the failure reason.
  5. Query DNS for exactly that name:
dig +short TXT selector1._domainkey.example.com
dig +short CNAME selector1._domainkey.example.com

You can also paste the headers into our email header analyzer. The DKIM glossary entry explains the record format.

The failure reason narrows things down. "Key not found" or "no key for signature" points to DNS (fixes 1 to 4). "Body hash did not verify" points to a modified message (fix 5). A signature that verifies but fails DMARC alignment points to fix 6.

Fix 2: make the selector and host match

Publish the record at exactly {s}._domainkey.{d}. Many DNS panels append the zone automatically, so enter only selector1._domainkey as the host, not selector1._domainkey.example.com. If dig shows selector1._domainkey.example.com.example.com, that is the doubled-domain mistake.

If you rotated keys, the server may still sign with the old selector. Check the s= value in a fresh message, not in your provider's dashboard.

Fix 3: clean up the TXT value

A DKIM TXT record looks like this in zone-file form:

selector1._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."

The quotation marks belong to zone-file syntax. Most web panels add them for you. If you paste them in too, the stored value can contain literal quote characters and the key will not parse.

  • The p= value must be one continuous base64 string. Remove spaces and line breaks picked up while copying.
  • A 2048-bit key exceeds the 255-character limit of a single TXT string, so it has to be stored as several quoted strings that resolvers join. Some DNS hosts do this for you; others need you to do it. Check your host's help page on long TXT records.
  • If you are unsure of the format, generate it with our DKIM generator and compare.

Fix 4: turn off the Cloudflare proxy on CNAME DKIM records

Microsoft 365 and some other providers ask you to publish DKIM as CNAME records. In Cloudflare those can be Proxied (orange cloud). For DKIM they must be DNS only (gray cloud). If the proxy is enabled, DNS lookups return Cloudflare's IP addresses instead of the CNAME target, and DKIM verification fails.

  1. In Cloudflare, open your domain and go to DNS > Records.
  2. Find the selector1._domainkey and selector2._domainkey records.
  3. Click the orange cloud so it turns gray and the status reads DNS only, then save.

TXT and MX records are not proxyable in Cloudflare; only records that resolve to a web-facing address, like CNAME and A records, show the proxy toggle. So if your DKIM key is a plain TXT record, the proxy is not your problem.

Do not retype provider values

For Microsoft 365, copy the CNAME names and targets exactly as the Defender portal shows them. The target format includes your domain with dashes and a tenant-specific part, and hand-typed values are a common source of failures.

Fix 5: retest after propagation, from a fresh message

If you published the record minutes ago, some resolvers may still hold the earlier "does not exist" answer. How long that lasts depends on your zone's TTL and SOA settings; it can be minutes or a few hours. Check against more than one public resolver:

dig +short TXT selector1._domainkey.example.com @1.1.1.1
dig +short TXT selector1._domainkey.example.com @8.8.8.8

When both return the key, send a new message and run a new mail-tester test. A message signed before the key existed, or before the server switched to the new key, will fail forever.

Fix 6: stop anything that edits the message after signing

If DNS is correct and the reason is "body hash did not verify", something changed the message between the signer and the receiver.

  • A gateway or relay that appends a disclaimer, footer or "external sender" banner after your server signs.
  • A tool that rewrites links or HTML after signing, such as a signature or tracking add-on.
  • Signing in the wrong order on self-hosted stacks (Mailcow, Stalwart and similar): the DKIM step must run last. Check the order of filters or milters, and confirm the private key on the server is the pair of the public key in DNS.

Move signing to the final outbound hop, or remove the modification. With c=relaxed/relaxed, whitespace changes are tolerated, but added text is not.

Fix 7: make d= match your From domain

Two common cases:

  • Microsoft 365. If you enable DKIM yourself, the signing domain will be the same as the domain in the From: address. Until then, mail from your custom domain may not carry a signature with your domain. In the Defender portal, open the DKIM page under Email authentication settings, publish the two CNAME records it shows, then turn on Sign messages for this domain with DKIM signatures. Microsoft's guide is How to use DKIM for email in your custom domain.
  • Other providers (Brevo, for example). If d= is the provider's domain while From is yours, the signature can verify and still not align. Look for the provider's domain authentication step, publish what it asks for, and then check that new messages show d=example.com.

DMARC needs d= to match the From domain: exactly in strict mode, same organizational domain in relaxed mode. For all three records together, see how to set up SPF, DKIM and DMARC.

Fix 8: rename a selector with an underscore

RFC 6376 defines a selector as hostname-style labels, so an underscore inside the selector itself (my_key) is not compliant. Some software tolerates it and some validators reject it. If you chose the name yourself, use letters, digits and hyphens, such as mail2026, and update both the signer and the DNS record. If your provider chose it, you cannot change it, and the cause is probably elsewhere.

Which cause do you have

What you seeLikely causeFix
dig returns nothingWrong host name, doubled domain, or not propagated2, 5
dig on a CNAME returns Cloudflare IPsProxied record4
Value contains \" or p= looks brokenQuotes, spaces or truncated key3
Key found, "body hash did not verify"Message modified in transit6
Signature passes, DMARC says unalignedd= differs from From domain7
d= is an onmicrosoft.com domainCustom-domain DKIM not enabled7
Only old tests failMessage sent before the key existed5

For a second opinion, learndmarc.com walks through the SPF, DKIM and DMARC checks on a message you send it.

Checklist before you test again

  • The s= and d= values come from a message sent after your last change.
  • dig returns the key or CNAME at {s}._domainkey.{d} from two public resolvers.
  • No quote characters, spaces or line breaks sit inside p=.
  • CNAME-based DKIM records are DNS only on Cloudflare.
  • Nothing between your server and the recipient edits the body or headers.
  • d= is your From domain, or a domain in the same organization if DMARC is relaxed.

Do not trust one tool

Mail-tester is a single receiver. Confirm the result in the Authentication-Results header of a real mailbox, and publish DMARC with reporting so real receivers tell you about failures.

If nothing works

Contact your sending provider first (Microsoft 365 admin support, Brevo, Google Workspace or whoever signs the mail). They can see which key the server actually signs with. If the DNS record itself will not save or behaves oddly, contact your DNS host; for Cloudflare, use its community or support channels. Include:

  • the full raw headers of a fresh test message
  • the exact s= and d= values
  • dig output for the record from two resolvers
  • the send time with time zone
  • what you already tried
Subject: DKIM fails for example.com (s=selector1, d=example.com)

Hello,

Mail sent from user@example.com at 2026-11-30 14:05 UTC fails DKIM
verification. Mail-tester reports "Your DKIM signature is not valid."

Raw headers of the test message are attached. The signature uses
s=selector1 and d=example.com. dig output from 1.1.1.1 and 8.8.8.8 is
below. The record was published on 2026-11-30 and, for Cloudflare, set
to DNS only.

Can you confirm which key your servers sign with, and whether anything
in your outbound path modifies the message after signing?

Thank you.

Where Mailneo fits

Mailneo sends through the Gmail, Outlook or SMTP accounts you connect, so your mail provider creates the DKIM signature, not Mailneo. We cannot edit your DNS or sign on your behalf. For connected accounts, Mailneo checks your sending domain's SPF, DKIM and DMARC records and whether they authorize the provider you use, then tells you what to fix; you make the change at your DNS host. See the email accounts documentation.

Common questions

Can a DKIM record be correct and still fail in mail-tester?

Yes. The record can be right while the message was signed with a different selector, sent before the key existed, or altered after signing. Always compare the s= and d= in the message you actually sent.

Does mail-tester care about DMARC alignment?

Not as a separate check in the way a DMARC report does. A signature can verify and still be unaligned, which matters to DMARC. Use the DMARC generator to publish a record with reporting so receivers report alignment results.

Do TXT-based DKIM records need the Cloudflare proxy turned off?

No, TXT records cannot be proxied. The toggle only affects CNAME and A records, so it matters for CNAME-based DKIM setups like Microsoft 365.

How long should I wait before retesting?

Until dig returns the right answer from two public resolvers, which can take minutes or a few hours depending on TTL and caching. Then send a new message rather than rechecking an old one.

deliverabilitymail-testercloudflaremicrosoft-365error-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Related Articles

Deliverability

421 4.7.28 Gmail Unusual Rate of Unsolicited Mail: Fixes

The 421 4.7.28 error is a temporary Gmail deferral, not a block. Gmail is rate limiting a domain, DKIM domain or IP range it sees sending too much unwanted mail. Retries usually deliver, but you should fix authentication, unsubscribe headers, sending pace and shared infrastructure to stop it recurring.

Sohail Hussain|9 min read
Deliverability

451 4.7.500 Server busy: SMTP2GO stuck at Processed (Microsoft)

`451 4.7.500 Server busy. Please try again later.` is a temporary Microsoft deferral of the connecting IP, not a problem with your message. SMTP2GO keeps retrying, so mail sits at "Processed" for hours. Ask SMTP2GO to rotate your IP, move to a dedicated IP, or allow-list carefully in Defender.

Sohail Hussain|9 min read
Deliverability

535 5.7.139 Authentication unsuccessful: Microsoft 365 SMTP fixes

535 5.7.139 means Microsoft 365 refused the SMTP login even though the password may be right. The usual cause is that Authenticated SMTP is disabled for the mailbox or tenant, or Security Defaults blocks basic auth. Enable SMTP AUTH per mailbox, adjust Security Defaults or Conditional Access, use OAuth, or switch to a connector.

Sohail Hussain|9 min read
Deliverability

550 5.7.1 Message lacks SPF/DKIM/DMARC: Find the Real Cause

Outlook.com and Hotmail return "550 5.7.1 Message rejected: Message lacks SPF/DKIM/DMARC Auth Records" when a message fails their authentication checks. Valid SPF alone is not enough. Publish SPF, DKIM and an enforced DMARC policy for your From domain, then confirm the real cause in Message Trace.

Sohail Hussain|10 min read

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free