TutorialsDecember 14, 2025 12 min read

DKIM Configuration Tutorial: Email Signing Setup Guide

Complete DKIM setup tutorial with key generation, DNS configuration, and verification steps. Ensure email integrity with cryptographic signatures.

WizStatus Team
Author

DomainKeys Identified Mail (DKIM) adds a crucial layer of trust to email communication. It cryptographically signs outgoing messages to prove authenticity and integrity.

Unlike SPF, which only verifies the sending server, DKIM proves the email content hasn't been modified in transit. Proper DKIM implementation is essential for modern email authentication.

What is DKIM (DomainKeys Identified Mail)?

DKIM is an email authentication method using public-key cryptography. It verifies both the authenticity and integrity of email messages.

How DKIM Works

  1. Your mail server creates a digital signature using a private key
  2. The signature is added to the email as a DKIM-Signature header
  3. The public key is published in your DNS as a TXT record
  4. Receiving servers retrieve the public key and verify the signature
  5. Valid signatures confirm the email is authentic and unmodified

DKIM Signature Components

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
  d=example.com; s=google;
  h=from:to:subject:date:message-id;
  bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
  b=dGVzdCBzaWduYXR1cmUgZGF0YQ==
TagDescription
d=Signing domain
s=Selector (identifies the key pair)
b=The actual signature
bh=Body hash
h=Signed header fields

Why DKIM Configuration Matters

DKIM provides message integrity verification that SPF cannot offer.

Survives Forwarding

SPF often breaks when emails are forwarded through mailing lists or other servers. DKIM signatures remain valid because they're attached to the message itself.

In forwarding scenarios, DKIM may be your only path to DMARC compliance.

Builds Sender Reputation

Major email providers consider DKIM a strong positive signal:

  • Consistent DKIM signing improves inbox placement
  • Reduces likelihood of spam classification
  • Required by Google and Yahoo for bulk senders

Enables DMARC Alignment

For DMARC to pass, either SPF or DKIM must align with the header From domain. DKIM alignment is often more reliable.

Without DKIM, your DMARC effectiveness is significantly reduced, especially for forwarded messages.

How to Configure DKIM Step by Step

DKIM configuration involves three main steps: key generation, DNS publishing, and server configuration.

Step 1: Generate Key Pair

Generate a 2048-bit RSA key pair using OpenSSL:

# Generate private key
openssl genrsa -out private.key 2048

# Extract public key
openssl rsa -in private.key -pubout -out public.key
Never use 1024-bit keys. They are deprecated and considered insecure. Always use 2048-bit minimum.

Step 2: Publish Public Key in DNS

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

selector._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhki..."

Record format:

TagRequiredValue
v=YesAlways DKIM1
k=NoKey type, defaults to rsa
p=YesPublic key (base64, no line breaks)

Selector naming conventions:

  • Service name: google, sendgrid, mailchimp
  • Date-based: 202501, 2025jan
  • Sequential: selector1, selector2

Step 3: Configure Mail Server

Configuration varies by platform.

Google Workspace:

  1. Go to Admin console > Apps > Google Workspace > Gmail
  2. Select "Authenticate email"
  3. Choose your domain and generate DKIM key
  4. Copy the DNS record value and add to your DNS
  5. Click "Start authentication"

Microsoft 365:

  1. Go to Microsoft 365 Defender portal
  2. Navigate to Email & collaboration > Policies > DKIM
  3. Select your domain
  4. Enable DKIM signing
  5. Add the provided CNAME records to DNS

Postfix with OpenDKIM:

# Install OpenDKIM
apt-get install opendkim opendkim-tools

# Configure /etc/opendkim.conf
Domain                  example.com
KeyFile                 /etc/opendkim/keys/example.com/default.private
Selector                default

Step 4: Verify DKIM Configuration

Test your DKIM setup:

# Check DNS record exists
dig +short TXT selector._domainkey.example.com

# Send test email and check headers
# Look for: dkim=pass header.d=example.com

Use online verification tools:

  • mail-tester.com
  • mxtoolbox.com/dkim.aspx
  • Google Admin Toolbox

DKIM Configuration Best Practices

Follow these practices for robust DKIM implementation.

Use Unique Selectors Per Service

Each email source should have its own selector:

google._domainkey.example.com       # Google Workspace
sendgrid._domainkey.example.com     # SendGrid
mailchimp._domainkey.example.com    # Mailchimp

Benefits:

  • Rotate keys independently
  • Identify which service signed a message
  • Revoke access without affecting other services

Implement Key Rotation

Rotate DKIM keys regularly, ideally annually:

  1. Generate new key pair with new selector
  2. Publish new public key in DNS
  3. Wait for DNS propagation (24-48 hours)
  4. Configure mail server to use new key
  5. Verify signing works correctly
  6. Remove old DNS record after TTL expires
Use date-based selectors like 202501 to easily track key age and rotation history.

Sign All Outgoing Email

Ensure consistent signing across all email types:

  • Transactional messages
  • Marketing campaigns
  • System notifications
  • Support replies

Inconsistent signing creates opportunities for spoofed unsigned messages.

Monitor DKIM Verification

Track DKIM verification through DMARC reports:

  • High failure rates may indicate key issues
  • Check for messages not being signed
  • Monitor for message modification in transit

Use Relaxed Canonicalization

Configure relaxed canonicalization to handle minor modifications:

DKIM-Signature: ... c=relaxed/relaxed; ...

This tolerates minor whitespace changes that sometimes occur in transit.

Common DKIM Issues and Solutions

Issue: DNS Record Too Long

Long keys may exceed DNS record limits.

Solution: Most DNS providers handle splitting automatically. If not:

selector._domainkey IN TXT ("v=DKIM1; k=rsa; p=MIIBIjANBgkqhki..."
                            "rest-of-the-key-here...")

Issue: Key Not Found

Receiving servers can't find your public key.

Troubleshooting:

  • Verify selector matches the signature
  • Check DNS propagation
  • Ensure TXT record syntax is correct
  • Remove extra quotes or spaces

Issue: Signature Verification Fails

The signature doesn't match the message.

Common causes:

  • Message modified in transit
  • Wrong private key used
  • Header field mismatch
  • Body modified by mail gateway

Conclusion

DKIM configuration is a critical investment in email deliverability and security. By cryptographically signing messages, you provide strong proof of authenticity and integrity.

Key takeaways:

  • Always use 2048-bit keys minimum
  • Use unique selectors for each sending service
  • Rotate keys regularly
  • Monitor verification through DMARC reports

Combined with SPF and DMARC, DKIM ensures your emails maintain trustworthiness throughout their journey.

Related Articles

BIMI Implementation Guide: Display Your Logo in Inboxes
Tutorials

BIMI Implementation Guide: Display Your Logo in Inboxes

Implement BIMI to show your brand logo in email clients. Requirements, VMC certificates, and setup steps for visual email authentication.
11 min read
Cold Email Deliverability: Avoid Spam Filters in 2026
Best Practices

Cold Email Deliverability: Avoid Spam Filters in 2026

Improve cold email deliverability with proven strategies. Domain warmup, authentication, content tips, and sending practices that work.
12 min read
DMARC Policy Implementation: From None to Reject
Tutorials

DMARC Policy Implementation: From None to Reject

Implement DMARC policies progressively with monitoring. Learn to analyze reports, achieve alignment, and protect your domain from spoofing.
14 min read

Start monitoring your infrastructure today

Put these insights into practice with WizStatus monitoring.

Try WizStatus Free