By Dave Kowalski · Network engineer with 27 years in email infrastructure and DNS. Ran mail systems for enterprises and mid-size companies since the late 90s.
DKIM: The Crypto Behind Email Authentication That Actually Works
First time I saw a DKIM-Signature header in the wild I had to look up what all those fields meant. That was back in 2005, and DKIM was still experimental. These days it's the difference between your email landing in the inbox or getting flagged as spam.
DKIM signs your outgoing emails with a cryptographic key. The receiving server checks the signature against a public key in your DNS. If it matches, the email is legit and hasn't been tampered with.
Think of it like a tamper-evident seal on a package. The seal alone doesn't prove who sent it, but combined with DNS, it does.
Why You Need DKIM
SPF checks the envelope sender. That works great until someone forwards the email. Once it's forwarded, the SPF check runs against the forwarder's server, which isn't authorized in your SPF record. SPF breaks. DKIM doesn't.
Here's the practical impact:
If you only implement one authentication method, make it SPF. But if you want your email to actually land in the inbox instead of spam, implement DKIM too.
How the Signing and Verification Work
DKIM uses RSA public-key cryptography. You generate two keys:
The Signing Process
When your mail server sends an email:
The Verification Process
When a receiving server gets the email:
The beauty of this system is that the private key never leaves your server. Even if someone compromises your DNS and replaces your public key, they'd need the corresponding private key to sign emails. And they don't have it.
DKIM Selectors
The selector is a label that identifies which public key to use. You can have multiple selectors active at the same time. This is how you rotate keys without breaking in-flight emails.
Here are the selectors I've collected over the years:
| Provider | Selector |
|---|---|
| Google Workspace | |
| Microsoft 365 | selector1, selector2 |
| Zoho | zoho |
| SendGrid | s1, s2 |
| Mailgun | mailgun |
| ProtonMail | protonmail |
| Amazon SES | ses |
| GoDaddy | default, d |
| FastMail | fm1, fm2, fm3 |
| Rackspace | rx |
| Yahoo Small Business | yahoo |
Our DKIM Lookup tool tries 55+ selectors automatically. If you don't know your selector, start there.
Setting Up DKIM
Google Workspace
Microsoft 365
Generic Setup (Any Provider)
What a DKIM-Signature Header Looks Like
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=example.com; s=google; t=1721234567;
bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
h=from:to:subject:date:message-id;
b=dzdVyOfAKCdXwPKbUqIxhDNEvCw2gQhLUKHv6QuGmHXL
8UxVxQJq3fM7PqWZcRZq7v3WJLX9CQ5eFJ2r4Y6NZA==
The fields:
DKIM Best Practices From the Trenches
Rotate Your Keys Every 6 Months
I schedule this in my calendar. Generate a new key pair, publish the new public key under a new selector, switch your mail server to sign with the new selector, then remove the old one after two weeks. This limits the damage if a key is compromised.
Use 2048-Bit Keys
Some providers default to 1024-bit. That's still secure, but 2048 gives you a wider safety margin. The performance cost is negligible. If your provider allows it, use 2048.
Never Put Your Private Key in DNS
I've actually seen this in production. Someone pasted the wrong file. The entire internet had access to their signing key. The public key goes in DNS. The private key stays on your server. These are different files.
Test Your Signature Regularly
Send an email to a test address, pull the raw headers, and check the signature. Or drop the headers into our Header Analyzer. It shows you exactly what the receiving server saw.
Common DKIM Failures and Fixes
| Problem | What's Happening |
|---|---|
| Record not found at [selector]._domainkey.[domain] | Wrong selector, wrong domain, or the record hasn't propagated. Use our DKIM Lookup tool to check |
| Public key syntax error | The DNS record format is wrong. It should start with v=DKIM1; k=rsa; p=... |
| Signature doesn't verify | The private key on your server doesn't match the public key in DNS. Regenerate both |
| Key too short (under 1024 bits) | Generate a new key pair with 2048-bit key |
| Multiple DKIM records for the same selector | Remove duplicates. Only one TXT record per selector allowed |
| DKIM passes but DMARC fails | Check domain alignment. The d= domain in the signature must match the From address (or be a subdomain with relaxed alignment) |
Verify Your DKIM Setup
Use the DKIM Lookup tool to check your public key in DNS. Use the Header Analyzer to check the signature on a real email you've sent. If both pass, you're good.