February 4, 2026 11 min read

What Is DKIM and How Does It Work?

DKIM (DomainKeys Identified Mail) is an email authentication protocol that adds a cryptographic signature to your messages, proving they were authorized by your domain and have not been altered in transit. When you send an email, your mail server signs specific headers and the message body using a private key. Receiving servers verify this signature using your public key published in DNS.

While SPF tells receivers which servers can send your email, DKIM proves that the email content is authentic and unchanged. Together with SPF and DMARC, DKIM forms the foundation of modern email authentication.

We implement DKIM for organizations sending millions of messages, and proper configuration is essential for deliverability. This guide explains how DKIM works, how to set it up, and how to avoid common implementation mistakes.

How DKIM Works

DKIM uses public key cryptography. Your mail server holds a private key that signs outgoing messages. You publish the corresponding public key in DNS. Receiving servers use this public key to verify that the signature is valid.

The Signing Process

  1. Your mail server selects specific headers and the message body to sign
  2. It creates a hash of this content
  3. It encrypts the hash using your private key
  4. It adds the encrypted hash as a DKIM-Signature header

The Verification Process

  1. Receiving server reads the DKIM-Signature header
  2. It queries your DNS for the public key using the selector specified in the signature
  3. It decrypts the signature hash using your public key
  4. It independently calculates a hash of the signed content
  5. If the hashes match, DKIM passes. If not, it fails.

The DKIM-Signature Header

DKIM adds a header to every signed message. Understanding its components helps with troubleshooting:

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=example.com; s=selector1;
 h=from:to:subject:date:message-id;
 bh=base64hash...;
 b=signature...

Setting Up DKIM

Step 1: Generate a Key Pair

Generate a public/private key pair. Most email services provide this automatically. If generating manually, use OpenSSL:

openssl genrsa -out dkim_private.pem 2048
openssl rsa -in dkim_private.pem -pubout -out dkim_public.pem

Use 2048-bit keys for security. The private key stays on your mail server. The public key goes in DNS.

Step 2: Publish the Public Key in DNS

Create a TXT record at: selector._domainkey.yourdomain.com

The value contains your public key:

v=DKIM1; k=rsa; p=MIIBIjANBgkqhki...

Step 3: Configure Your Mail Server

Configure your mail server or email service to sign outgoing messages with your private key. Each email service has its own configuration method. Check your provider's documentation for specific steps.

Step 4: Test and Verify

Send a test email and check the Authentication-Results header. You should see dkim=pass. Use online tools to verify your DKIM DNS record is correctly published.

DKIM Selectors

Selectors allow you to have multiple DKIM keys for the same domain. This is useful for:

Common selector naming conventions:

Key Rotation

Rotate DKIM keys periodically to maintain security:

  1. Generate a new key pair with a new selector
  2. Publish the new public key in DNS
  3. Wait for DNS propagation (at least 24 hours)
  4. Switch your signing configuration to use the new key
  5. Keep the old public key published for 1-2 weeks
  6. Remove the old DNS record once you are confident all emails are using the new key

Why Keep Old Keys Published?

Emails in transit or delayed for retry may still carry signatures from the old key. Removing the old public key immediately causes these messages to fail DKIM verification.

Canonicalization

Canonicalization defines how the message is normalized before hashing. Two methods exist:

The c=relaxed/relaxed setting applies relaxed canonicalization to both headers and body. This is the recommended setting because some mail servers and gateways make minor formatting changes that would break simple canonicalization.

Common DKIM Problems

Signature Breaks After Forwarding

Email forwarding and mailing lists often modify messages, breaking DKIM signatures. This is a known limitation. ARC (Authenticated Received Chain) was developed to address this by preserving authentication results through forwarding chains.

Key Not Found Errors

If receivers cannot find your public key, check:

Body Hash Mismatch

This indicates the message body was modified after signing. Common causes include security gateways adding footers, antivirus scanners modifying content, or encoding changes during transit.

DKIM and DMARC Alignment

For DKIM to contribute to DMARC pass, the signing domain (the d= value in the DKIM signature) must align with the domain in the From header. Alignment can be relaxed (subdomains allowed) or strict (exact match required).

If you sign with d=mail.example.com but send from [email protected], relaxed alignment passes but strict alignment fails.

Frequently Asked Questions

What does DKIM stand for?
DKIM stands for DomainKeys Identified Mail. It is an email authentication protocol that uses cryptographic signatures to verify that an email was authorized by the domain owner and was not modified in transit.
What key size should I use for DKIM?
Use a minimum of 1024-bit keys, but 2048-bit keys are recommended for better security. Some providers now require 2048-bit keys. Keys larger than 2048 bits may not fit in a single DNS TXT record without special handling.
How often should I rotate DKIM keys?
Rotate DKIM keys at least annually. Some security policies recommend rotating every 6 months. When rotating, publish the new key before switching your signing configuration, and keep the old key published for at least a week after the switch.
Can DKIM signatures break?
Yes, DKIM signatures can break if the message is modified after signing. Mailing lists, email forwarding services, and security gateways that alter message content or headers can invalidate DKIM signatures. Using relaxed canonicalization helps prevent some of these issues.

Ready to Improve Your Email Deliverability?

SortedIQ helps high-volume senders maximize inbox placement and sender reputation.

Talk to Our Team