Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

DKIM shows 'bad version' or 'unknown key type' because the DNS key record is malformed

Errordkim=neutral (bad version)

Short answer

These results mean the receiver found your DKIM key record but could not use it. The record must start with v=DKIM1 exactly, use a key type the verifier knows, such as k=rsa, carry the public key in p=, and be the only record at the selector. A bad paste into DNS is the usual cause.

  • Applies to RFC 6376, dig
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Fetch the key record exactly as the receiver sees it. The name is selector, then _domainkey, then your domain.

    dig +short TXT selector1._domainkey.example.com
  2. 2Match what you see, then jump to its fix

    1. 1The answer begins with something other than v=DKIM1, such as a typo, a different value or the key tags first.The version tag is not exactly DKIM1, or is not firstFix
    2. 2dkim=fail (unknown key type) while the version looks right.The key type tag has a value the verifier does not recogniseFix
    3. 3The p= value is empty, ends early, or contains spaces and quotes from a bad copy.p= is empty, truncated or pasted with extra charactersFix
    4. 4dig returns two or more answers for the selector name.More than one TXT record exists at the selectorFix

What does the error look like?

  • dkim=neutral (bad version)
  • dkim=fail (unknown key type)

Cause 1 of 4

The version tag is not exactly DKIM1, or is not first

1Check

RFC 6376 says v=, if present, must be DKIM1 and must be the first tag. Records with any other value are discarded, and the comparison is exact, so DKIM1.0 is not accepted.

dig +short TXT selector1._domainkey.example.com | head -c 80

2Fix

Rewrite the record so it begins with v=DKIM1; followed by the other tags.

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

3Verify

dig shows a record starting v=DKIM1, and a new test message shows dkim=pass.

dig +short TXT selector1._domainkey.example.com

Confirmed by rfc-editor.org

Did this fix it?

Cause 2 of 4

The key type tag has a value the verifier does not recognise

1Check

k= is optional and defaults to rsa. An unrecognised key type makes the key unusable.

dig +short TXT selector1._domainkey.example.com

2Fix

Use k=rsa, or remove the k= tag so the default applies, and make sure p= holds the public key your signer actually uses.

"v=DKIM1; k=rsa; p=PUBLIC_KEY_BASE64"

3Verify

The next test message shows dkim=pass at Gmail and Yahoo.

dig +short TXT selector1._domainkey.example.com

Confirmed by rfc-editor.org

Did this fix it?

Cause 3 of 4

p= is empty, truncated or pasted with extra characters

1Check

p= is required and holds the base64 public key. An empty value means the key has been revoked. Long keys are split into several quoted strings in DNS, and the strings are joined without added spaces.

dig +short TXT selector1._domainkey.example.com | wc -c

2Fix

Publish the full key again from the file your signer generated, as one record. Keep quotes only around each string, with no extra spaces inside the key.

selector1._domainkey.example.com.  IN  TXT  ( "v=DKIM1; k=rsa; "
    "p=MIIBIjANBgkq...first part"
    "second part...IDAQAB" )

3Verify

The joined answer is one complete key, and dkim=pass appears.

dig +short TXT selector1._domainkey.example.com

Confirmed by rfc-editor.org

Did this fix it?

Cause 4 of 4

More than one TXT record exists at the selector

1Check

RFC 6376 says the record set for a selector should contain only one record, and with several the results are undefined.

dig +short TXT selector1._domainkey.example.com

2Fix

Delete the old or duplicate records, leaving only the current key.

; keep only one TXT record at selector1._domainkey

3Verify

dig returns exactly one answer.

dig +short TXT selector1._domainkey.example.com | wc -l

Confirmed by rfc-editor.org

Did this fix it?

How do I stop it coming back?

  • Copy the record from the signer's generated file or the provider's screen, not by retyping.
  • Give every new key a new selector and remove the old record after the switch.
  • Send a test message to a Gmail and a Yahoo address and read the authentication result before turning on a strict DMARC policy.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Email

Django send_mail fails or hangs with an SSL error

smtplib.SMTPException raised from send_mail()

Django has two secure modes that must not be mixed: EMAIL_USE_TLS for explicit TLS (STARTTLS, usually port 587) and EMAIL_USE_SSL for implicit TLS (usually port 465).

4 causes, each with a fix

Email

Mail from your own domain keeps landing in the spam folder

dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=example.com

Open a message that went to spam and read its Authentication-Results header: it shows whether SPF, DKIM and DMARC passed, and for which domain.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.