Master DKIM email authentication: understand how DKIM signatures work, how to set up DKIM records, and troubleshoot common DKIM validation issues.
DKIM Authentication: How to Sign and Verify Your Emails
What is DKIM?
DKIM (DomainKeys Identified Mail) is an email authentication method that uses cryptographic signatures to verify that an email was actually sent by the claimed domain and hasn't been tampered with in transit.
How DKIM Works
DKIM adds a digital signature to email headers:
- Sending server signs email with private key
- Email header contains DKIM-Signature
- Receiving server retrieves public key from DNS
- Verification of signature using public key
- Result: Pass or Fail
DKIM Record Structure
DNS Record
selector._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
Components:
selector: Identifier (e.g., "google", "default")v=DKIM1: DKIM versionk=rsa: Key type (RSA)p=...: Public key (base64 encoded)
Email Header
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=selector;
h=from:to:subject:date;
bh=base64hash;
b=signature
Setting Up DKIM
Step 1: Generate Key Pair
# Generate 2048-bit RSA key
openssl genrsa -out dkim_private.pem 2048
openssl rsa -in dkim_private.pem -pubout -out dkim_public.pem
Step 2: Configure Mail Server
Postfix + OpenDKIM:
# /etc/opendkim.conf
Domain example.com
Selector default
KeyFile /etc/opendkim/keys/default.private
Step 3: Publish DNS Record
Type: TXT
Name: default._domainkey
Value: v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA...
TTL: 3600
Common DKIM Selectors
default: Generic selectorgoogle: Google Workspacek1,k2: Multiple keys (rotation)s1,s2: SendGridm1: Mailchimp
Checking DKIM Records
Use MXToolbox.eu DKIM checker:
- Enter domain
- Enter selector (or try common ones)
- Tool fetches public key from DNS
- Validates record syntax
- Shows key details
Common DKIM Issues
1. Selector Not Found
Error:
DKIM record not found for selector 'default'
Solution: Try other selectors
- google._domainkey
- k1._domainkey
- selector1._domainkey
2. Invalid Public Key
Problem: Syntax error in DNS record
v=DKIM1; k=rsa; p=INVALID-KEY
Solution: Re-generate and re-publish key
3. Key Too Short
Problem: Key < 1024 bits (insecure)
Solution: Use 2048-bit key minimum
openssl genrsa -out key.pem 2048
4. Multiple DKIM Records
Problem: Two+ TXT records for same selector
Solution: Only ONE record per selector
DKIM Best Practices
✅ 2048-bit keys - More secure
✅ Rotate keys - Every 6-12 months
✅ Multiple selectors - For key rotation
✅ Sign all headers - Especially From, Subject, Date
✅ Test thoroughly - Send test emails
DKIM vs SPF vs DMARC
| Protocol | Purpose | How It Works |
|---|---|---|
| SPF | Authorize sending IPs | DNS TXT record |
| DKIM | Sign email content | Cryptographic signature |
| DMARC | Policy enforcement | SPF + DKIM alignment |
Use all three for complete protection! 🛡️
Troubleshooting DKIM
Signature Verification Failed
- Check DNS record published correctly
- Verify selector matches email header
- Ensure public/private keys match
- Check for whitespace in DNS record
Headers Not Signed
Problem: Important headers excluded
Solution: Configure mail server to sign:
h=from:to:subject:date:message-id
DKIM for Email Services
Google Workspace
Selector: google._domainkey
Auto-configured by Google
Microsoft 365
Selector: selector1._domainkey, selector2._domainkey
Two selectors for key rotation
SendGrid
Selectors: s1._domainkey, s2._domainkey
Configure in SendGrid dashboard
Conclusion
DKIM is critical for:
- Preventing email tampering
- Improving deliverability
- Building sender reputation
- Passing DMARC alignment
Implement DKIM correctly to ensure your emails reach the inbox.
Check your DKIM configuration with our free DKIM checker.
Related Tools:
- SPF Validation - Authorize sending servers
- DMARC Lookup - Email policy enforcement
- Email Health Check - Complete analysis