dkim=fail in the Authentication-Results header. Nothing changed in your DNS zone — and that is exactly the problem. The new server is signing with a private key that does not match the public key still sitting in your DNS TXT record, or it is using a different selector entirely.
This guide walks through the CLI checks to find the mismatch, confirm what your new server is actually signing with, and verify the fix.
How DKIM Signing and Validation Work Together
DKIM-Signature header. That header contains (among other things):
d=— the signing domain (e.g.,example.com)s=— the selector (e.g.,default,mail,s1,20230601)b=— the actual cryptographic signaturebh=— a hash of the message body
selector._domainkey.example.com, retrieves the public key from the TXT record, and uses it to verify the signature. If the public key in DNS does not match the private key that signed the message, validation fails. Period.
During a migration, three things commonly go wrong:
- The new server generates a new key pair, but nobody updated DNS with the new public key.
- The new server uses a different selector name, and DNS still only has the old selector.
- DNS was updated, but the TXT record got truncated or mangled (especially with long 2048-bit keys split across multiple strings).
Step 1: Read the DKIM-Signature Header From a Real Message
DKIM-Signature header. You need two values from it:
TEXT
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=mail2024;
h=from:to:subject:date:message-id;
bh=abcdef1234...;
b=GHIJKL5678...s= value (mail2024 in this illustrative example) and the d= value (example.com). These tell you exactly which DNS record the receiving server will query: mail2024._domainkey.example.com.
Also check the Authentication-Results header added by the receiving server. It typically says something like dkim=fail (body hash did not verify) or dkim=fail (no key for signature). The reason in parentheses matters — "no key" means DNS lookup returned nothing; "body hash did not verify" means the key was found but the signature did not match.
For more on reading these headers, see Reading Authentication-Results Headers to Fix DMARC Alignment.
Step 2: Query DNS for the Selector Your Server Is Using
BASH
dig TXT mail2024._domainkey.example.com +shortv=DKIM1; k=rsa; p=MIIBIjANBgkq... (the public key).
Possible bad outcomes:
- Empty response or NXDOMAIN. DNS has no record for this selector. The new server is signing with a selector that was never published. This is the most common post-migration failure.
- Record exists but uses the old key. The selector name happens to match, but the public key belongs to the old server's private key. Signature verification will fail.
- Record is truncated. Some DNS control panels silently cut TXT records longer than 255 characters. A 2048-bit RSA public key is roughly 400 characters and must be split into multiple quoted strings within a single TXT record. If the panel dropped the second half, the key is invalid.
BASH
dig CNAME mail2024._domainkey.example.com +shortStep 3: Confirm the Private Key on the New Server Matches the DNS Public Key
- Exim with cPanel/WHM: typically under
/var/cpanel/domain_keys/with one file per domain. - Postfix with OpenDKIM: the key path is defined in the
KeyTablefile, often under/etc/opendkim/keys/. - Exim with manual DKIM: check the Exim configuration for
dkim_private_key.
BASH
openssl rsa -in /path/to/private.key -pubout -outform PEM 2>/dev/nullBEGIN and END lines) should match the p= value in your DNS TXT record, ignoring whitespace and line breaks.
If they do not match, you have a key mismatch. Either:
- Update DNS with the public key that corresponds to the private key the new server is using, or
- Replace the private key on the server with one that matches what DNS already publishes (less common, since you typically do not have the old private key after migration).
Step 4: Check for Leftover Old Selectors
default and the new server uses mail2024, both records might exist in DNS. That is fine — old selectors do not cause failures on their own. But if the new server was accidentally configured to sign with the old selector name while using a new private key, validation breaks.
Query both selectors and compare:
dig TXT default._domainkey.example.com +shortdig TXT mail2024._domainkey.example.com +short
Step 5: Verify DMARC Alignment
d= domain in the DKIM signature matches (or is a subdomain of) the From: header domain. If your new server signs as d=mail.example.com but your From address is [email protected], DKIM passes but DMARC alignment fails unless your DMARC record uses adkim=r (relaxed mode, which allows subdomain matching).
Check your DMARC record:
BASH
dig TXT _dmarc.example.com +shortadkim= tag. If it says adkim=s (strict), the DKIM d= domain must exactly match the From domain. If it says adkim=r or is absent (relaxed is the default), subdomain matching is allowed.
If you are also sending through third-party services (marketing platforms, helpdesks), each one needs its own DKIM selector published in your DNS. Otherwise those messages will fail DKIM or fail DMARC alignment. See Added a New CRM or Helpdesk? Verify It Signs DKIM With Your Own Domain for that scenario.
Step 6: Send a Test and Confirm the Full Chain
dkim=passwith the correct selector and domaindmarc=passwith alignment confirmedspf=pass(separate from DKIM, but part of the overall authentication picture)
The Short Version
s= and d= values from the DKIM-Signature header, query that exact selector in DNS, and compare the public key to what the server's private key produces. Fix whichever side is wrong, wait for DNS propagation, and test again. The whole check takes five minutes once you know what to look for.