DKIM Configuration Complete Guide
DKIM (DomainKeys Identified Mail) adds cryptographic signatures to your emails, allowing receivers to verify authenticity and detect tampering. This guide covers everything from key generation to production deployment.
How DKIM Works
DKIM Record Structure
Generating DKIM Keys
Using OpenSSL (Standard Method)
-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAszLfGbitgbShFNHJp4Em 7jPMCvyFMKFQtxCO/HaY5qUwSKm4LabCp6wP8SNX6ldPejuGbVE7YG+yuuOL4ffP O69RZnRYftdE4bE6YNiQLTc9deGuuyI7S6BVEF7NbHIC30VVfENwY8pyoGk1lMgP d4sdZEet7yQHgAwWYT2lPehcg657viWkjtdyvuEc8X0eVDVZq2cDh2WK0tz+PHcU x7rx8iu1AG2JdJ779mjgu8tgTmE0dfuVbbI5jFZcXMCHfRgHQ/eP+0MX+18NC6KZ U1qwfJtjBxW3imudhCQv+97M2fLxcbtndvlBYyZdEXf053N1tkc6PstACpxlVvgF oQIDAQAB -----END PUBLIC KEY-----
Output:
Format for DNS Record
Remove headers and line breaks to create the DNS value:
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAszLfGbitgbShFNHJp4Em 7jPMCvyFMKFQtxCO/HaY5qUwSKm4LabCp6wP8SNX6ldPejuGbVE7YG+yuuOL4ffP O69RZRYftdE4bE6YNiQLTc9deGuuyI7S6BVEF7NbHIC30VVfENwY8pyoGk1lMgP d4sdZEet7yQHgAwWYT2lPehcg657viWkjtdyvuEc8X0eVDVZq2cDh2WK0tz+PHcU x7rx8iu1AG2JdJ779mjgu8tgTmE0dfuVbbI5jFZcXMCHfRgHQ/eP+0MX+18NC6KZ U1qwfJtjBxW3imudhCQv+97M2fLxcbtdvlBYyZdEXf053N1tkc6PstACpxlVvgF oQIDAQAB
DNS TXT Record Value:
Generating 4096-bit Keys (High Security)
Note: 4096-bit keys exceed DNS TXT record limits (255 chars per string). Most DNS providers handle splitting automatically, but verify your provider supports this.
Ed25519 Keys (Emerging Standard)
DNS Record for Ed25519:
Platform-Specific Configuration
Google Workspace
Admin Console Setup:
- Go to Admin Console → Apps → Google Workspace → Gmail
- Click Authenticate email
- Select your domain
- Click Generate new record
- Select 2048-bit key length
- Note the selector (e.g., )
- Copy the TXT record value
DNS Record:
- Wait 24-48 hours for propagation
- Return to Admin Console and click Start authentication
Microsoft 365
Exchange Admin Center Setup:
- Go to Exchange Admin Center → Mail flow → Rules
- Or use PowerShell:
DNS Records (CNAME):
Postfix (Linux Mail Server)
Install OpenDKIM:
Generate Keys:
Configure OpenDKIM (/etc/opendkim.conf):
Configure Key Table (/etc/opendkim/KeyTable):
Configure Signing Table (/etc/opendkim/SigningTable):
Configure Postfix (/etc/postfix/main.cf):
Start Services:
Amazon SES
Enable DKIM (AWS Console):
- Go to SES Console → Verified Identities
- Select your domain
- Go to Authentication tab → DKIM
- Click Generate DKIM tokens
- Add the provided CNAME records to DNS
DNS Records (CNAME):
Using AWS CLI:
SendGrid
Enable DKIM (Dashboard):
- Go to Settings → Sender Authentication
- Click Authenticate Your Domain
- Select DNS host and enter domain
- Add the provided DNS records
DNS Records:
DKIM Signature Header Explained
Canonicalization Explained
Key Rotation
Rotation Process
Rotation Script
Add this DNS record:
After DNS propagates, update these files: KeyTable: mail2026._domainkey.example.com example.com:mail2026:/etc/opendkim/keys/example.com/mail2026.private Then restart: systemctl restart opendkim
Testing and Verification
Verify DNS Record
"v=DKIM1; p=" Server: 192.168.1.1 Address: 192.168.1.1#53
Non-authoritative answer: mail._domainkey.example.com text = "v=DKIM1; p="
Authoritative answers can be found from:
mail._domainkey.example.com descriptive text "v=DKIM1; p="
Test with Email
Send a test email to a major provider (Gmail, Outlook) and check headers:
Online Testing Tools
- mail-tester.com - Send email, get detailed report
- dkimvalidator.com - Check DNS record format
- mxtoolbox.com/dkim.aspx - DNS lookup and validation
Command-Line Testing
Troubleshooting
Common Errors
| Error | Cause | Solution |
|---|---|---|
| DNS record missing or not propagated | Check DNS, wait for propagation | |
| Key mismatch or message modified | Verify key pair match, check intermediaries | |
| Body modified in transit | Use relaxed canonicalization | |
| DNS timeout | Check DNS server availability | |
| Malformed DNS record | Fix syntax errors in TXT record |
Debug Checklist
Best Practices
Security Recommendations
- Use 2048-bit RSA keys minimum - 1024-bit is deprecated
- Rotate keys annually - More frequently for high-security
- Protect private keys - Restrict file permissions, consider HSM
- Use relaxed canonicalization - Better survivability
- Sign important headers - from, to, subject, date, message-id
- Monitor DMARC reports - Detect misconfigurations early
Selector Naming Conventions
| Convention | Example | Use Case |
|---|---|---|
| Service-based | , | Third-party email services |
| Date-based | , | Key rotation tracking |
| Sequential | , , | Simple rotation |
| Environment | , | Multiple environments |
Multiple Sender Configuration
Related Resources
- Email Authentication Complete Guide - Hub article
- SPF Record Syntax Guide - Complete SPF reference
- DMARC Deployment Guide - Tie SPF + DKIM together
- Email Header Analysis - Interpret results
Tools
- DKIM Record Generator - Create DKIM keys and DNS records
- DNS Lookup - Verify your DKIM DNS record
- DMARC Record Generator - Complete your email authentication