Deliverability

DKIM_INVALID: DKIM or DK signature exists, but is not valid

DKIM_INVALID means SpamAssassin found a DKIM signature but could not verify it. The usual causes are a message altered after signing, a DNS public key that doesn't match the signing key, or a malformed key record. Read the Authentication-Results header to see which one you have, then fix the signer or the DNS record.

Sohail HussainSohail Hussain10 min read

Short answer

  • DKIM_INVALID means the message carries a DKIM-Signature header, but verification failed. Open the full headers and read the Authentication-Results line to see why.
  • The usual causes are content changed after signing, a DNS public key that does not match the signing key, or a malformed DNS record. Fix the one the headers point to, then send a fresh test message.

You ran a message through SpamAssassin and the report shows this:

DKIM_INVALID DKIM or DK signature exists, but is not valid

The message has a signature, so someone tried to sign it. The check at your end did not pass. This article explains how to find out which part broke and how to repair it.

Why it happens

DKIM_INVALID is a rule in SpamAssassin's DKIM plugin. It fires when at least one signature is present and none of the checks succeeded. The rule does not say who is at fault. The sender, a relay in the middle or your own scanning server can each cause it.

It also adds only a small score by default. It is not a rejection on its own. Whether the message is blocked depends on your threshold and on whether DMARC fails at the recipient. A message with one invalid signature and one valid signature from the From domain can still pass DMARC.

Causes, most common first:

  1. The message changed after signing. A footer, disclaimer, subject tag, rewritten link or re-encoded body breaks the body hash or a signed header.
  2. The DNS key does not match the signing key. This often follows a key rotation or a mail server migration.
  3. The DNS record is malformed. Split strings, stray quotes, a doubled zone name or an empty p= tag.
  4. Your own scanner is the problem. A broken resolver, a disabled DNS test or a filter that rewrites the message before SpamAssassin sees it.
  5. The signature is expired or the saved file was altered. Old messages and re-saved .eml files often fail.

People on self-hosted setups (for example Virtualmin with SpamAssassin) report this rule firing on mail that other checkers pass, which points at cause 4 more often than you might expect.

Read the headers first

Before changing anything, open the full raw headers of the flagged message. You need two things:

  1. The X-Spam-Status line, which lists the rules that hit, including DKIM_INVALID.
  2. The Authentication-Results header (or the X-Spam-Report), which usually gives the reason, such as dkim=fail (bad signature) or dkim=fail (body hash did not verify). Wording varies by verifier.

Then read the DKIM-Signature header and note d= (signing domain), s= (selector) and bh= (body hash). The public key sits in a TXT record at {selector}._domainkey.{domain}. Query it from a terminal:

dig +short TXT s1._domainkey.example.com

Swap in your own selector and domain. If you want help reading the headers, paste them into our email header analyzer, or read understanding email headers.

Verification resultLikely causeFirst fix
body hash did not verifyBody changed after signingSign after the last edit
bad signatureSigned header changed, or key mismatchCompare DNS key to signer key
key not found or no key for signatureSelector record missing or at the wrong namePublish it at the right host
permerror or key syntax errorMalformed DNS recordRepublish a clean record
signature expiredx= time passed, or replayed lateTest with a fresh message

The neighboring rules help you read the whole report: DKIM_SIGNED only means a signature is present, DKIM_VALID means at least one verified, and DKIM_VALID_AU means a valid signature from the From domain.

Step-by-step fixes

Fix 1: stop changes after signing

This is the most common cause on messages that pass through more than one system. Typical culprits:

  • A gateway or receiving server that appends a disclaimer or footer.
  • A mailing list that adds a subject tag or footer.
  • A link-rewriting or click-tracking layer that runs after the signature is added.
  • A relay that changes line endings, whitespace or 8-bit encoding.

To confirm, look for body hash did not verify on a message that did not travel straight from the signer to you.

  1. List every system the message touches between composing and delivery.
  2. Move footers, tracking rewrites and disclaimers to a step that runs before signing.
  3. Make the last system that edits the message the one that signs it.
  4. If your signer allows it, set relaxed canonicalization (c=relaxed/relaxed in the signature). It tolerates harmless whitespace and header-folding changes, though not real content edits.

Mailing lists

If a mailing list modifies the message, you cannot fix that from the sender side alone. The list should re-sign with its own domain. Whether the original message still aligns for DMARC is a separate question.

Fix 2: make the DNS key match the signer

To confirm, you see bad signature while the body hash is fine and the DNS record exists. This happens after a key rotation, when you regenerate keys in one place but publish the old record, or when two systems sign with the same selector but different keys.

  1. Find the selector in the s= tag of the failing signature.
  2. Look up the TXT record at {selector}._domainkey.example.com with dig.
  3. On the signing server, display the public key it expects. The tool varies: OpenDKIM, Exim, a Postfix milter or your control panel.
  4. Make the two identical. Either replace the DNS value with the current public key, or reconfigure the signer to use the key DNS holds.
  5. Wait for the old record's TTL to expire before retesting.

Give each sending system its own selector, such as s1 for your server and a different one for a provider. Never reuse one selector for two keys.

Fix 3: repair a broken DNS record

To confirm, you see key syntax error, permerror, or a record that looks cut off. A healthy record looks like this:

s1._domainkey.example.com.  IN  TXT  "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."

Typical breakage:

  • A 2048-bit key is a long string, and each TXT string is limited to 255 characters. It must be split into several quoted strings inside one record. Many DNS panels do this for you; some do not, and some add a stray space or newline.
  • Curly quotes pasted in, or the value wrapped in quotes twice.
  • The record landed at s1._domainkey.example.com.example.com because the panel appends the zone name automatically.
  • An empty p= tag, which means the key was revoked.
  • A leftover t=y (testing mode) flag, which some receivers treat differently.

Re-query with dig, read the full output, and republish if the string is truncated. To generate a clean record, use our DKIM generator. The glossary entries on DKIM and DNS records cover the basics.

Fix 4: check your own SpamAssassin server

If outside tools (a public DKIM checker, or a test message to Gmail) show the signature passing but your SpamAssassin box says invalid, suspect your side.

  1. Confirm the local resolver can reach the internet and does not time out on TXT lookups.
  2. Confirm SpamAssassin's DNS tests are enabled.
  3. Confirm the DKIM plugin is loaded (look in the .pre files in your SpamAssassin config directory).
  4. Flush the resolver cache in case a stale negative answer is stored, then rescan.
  5. Run the original saved file through the scanner directly:
spamassassin -D dkim < message.eml

If it passes there but fails in the live pipeline, something in your pipeline (a milter or filter that reformats the message) is altering it before SpamAssassin runs.

Fix 5: rule out expiry and re-saved files

Signatures can carry an expiry (x=). A message you rescan weeks later, or one that arrives very late, may verify as expired. A .eml that was opened and re-saved by a mail client also often fails, because the client rewrote line endings or headers. Save raw messages from the server, not from a client.

Test with a fresh message

Do not judge a fix by rescanning the old failing file. Its signature, expiry and any in-transit edits are already fixed in that file. Send a new message after each change.

Checklist before you try again

  • The failing result is read from Authentication-Results, not guessed.
  • The selector in s= matches the host you queried in DNS.
  • The DNS TXT value is one record, complete, with no stray quotes or doubled zone name.
  • The signer's key and the published key are the same pair.
  • Nothing edits the message after the signature is added.
  • The d= domain matches your From domain, so DMARC can align.
  • The old record's TTL has expired.

Test after fixing

  1. Send a fresh message from the affected system to a mailbox where you can read headers.
  2. Confirm dkim=pass in Authentication-Results and DKIM_VALID (ideally DKIM_VALID_AU) in the SpamAssassin report.
  3. Check that alignment holds. See what DMARC is if that part is new, and the SPF, DKIM and DMARC setup guide for the full record set.

DNS changes can take as long as the record's TTL. If you can, lower the TTL before a planned change.

If nothing works

If the message comes from a provider you do not control and the signature fails at the first hop, contact that provider's support. If it fails only after your own gateway, the problem is local; contact whoever runs that gateway or your mail host. Include:

  • The full raw headers.
  • The selector and domain from the DKIM-Signature.
  • The exact Authentication-Results line.
  • The send time with time zone.
  • What you already tried.
Subject: DKIM signature fails verification (DKIM_INVALID)

Hello,

Messages from {your-domain} show DKIM_INVALID in SpamAssassin.
Signing domain (d=): {your-domain}
Selector (s=): {selector}
Authentication-Results: {paste the exact line}
Sent at: {date, time, time zone}

Raw headers are attached. I already compared the DNS TXT record at
{selector}._domainkey.{your-domain} with the signing key and checked
that nothing edits the message after signing. Can you confirm which
key you sign with and whether anything modifies the message after
the signature is added?

Thank you.

Where Mailneo fits

Mailneo helps with one part of this. For mailboxes you connect, it checks your sending domain's SPF, DKIM and DMARC records and whether they authorize the provider you use, which can surface a missing DKIM record before you send. It does not edit your DNS, fix a signature broken by a gateway or mailing list, or diagnose what happened to a single message in transit. You make those changes at your registrar, DNS host or mail server. For one flagged message, the free header analyzer linked above is the quicker check.

Common questions

Does DKIM_INVALID mean my email went to spam?

Not by itself. The rule adds a small score, and the outcome depends on your threshold and the other rules that hit. DMARC failing at the recipient is the bigger risk.

Can a message pass DMARC with DKIM_INVALID?

Yes, if another signature from the From domain verifies, or if SPF passes and aligns. DMARC needs one aligned pass, not all of them.

Why does the signature pass in Gmail but fail on my server?

That points to your side: the resolver, a disabled DNS test, a missing DKIM plugin or a filter that rewrites the message before SpamAssassin scans it.

Is a DKIM record with t=y a problem?

It marks the domain as testing DKIM, and some receivers treat that differently. Remove it once your signing works, unless you are still testing.

deliverabilityspamassassinerror-codes
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

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

Related Articles

Deliverability

0x800ccc0e: Outlook Unable to Connect to SMTP Server, Fixed

Outlook error 0x800ccc0e means the app could not open a connection to your outgoing (SMTP) server. Usually the port, encryption setting or password is wrong, or antivirus, a firewall or your ISP is blocking it. Set port 587 with STARTTLS, turn on SMTP authentication, and test again.

Sohail Hussain|10 min read
Deliverability

SocketLabs "421 4.5.1 Too many errors" blacklist: how to fix it

`421 4.5.1 Too many errors, you have been temporarily blacklisted` means a SocketLabs server saw repeated auth or bad-address errors from your IP and paused it. Stop whatever is retrying, fix credentials and invalid recipients, clear the queue, and wait. The block usually lifts within minutes, but returns if retries resume.

Sohail Hussain|9 min read
Deliverability

421-4.7.0 Gmail Has Detected This Message Is Suspicious: Fix

The 421-4.7.0 "suspicious due to the nature of the content and/or the links" error means Gmail's content filter rejected your message after DATA, not an authentication check. Remove click tracking or move it to your own domain, drop URL shorteners, check link reputation, then retest with a plain message.

Sohail Hussain|10 min read
Deliverability

421 4.7.0 IP not in whitelist for RCPT domain: what it means

The error 421 4.7.0 IP not in whitelist for RCPT domain means the recipient's mail gateway, usually Mimecast in reports, only accepts connections from approved IPs, and the Google sending IP isn't on that list. The fix is on the recipient side: their admin must allow the IPs or change the mail routing.

Sohail Hussain|9 min read

Ready to supercharge your email marketing?

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

Get Started Free