How DKIM works
DKIM uses a key pair. The private key stays on the sending server and signs each message; the public key sits in your DNS where anyone can use it to check the signature. Only the holder of the private key can produce a signature that verifies.
The sending server signs the email
It hashes the body and selected headers (from, subject, date) and signs the result with your private key.The signature goes in the headers
It is added as a DKIM-Signature header, which names your domain and the selector of the key used.The receiving server verifies
It fetches your public key from DNS, recomputes the hashes and checks them against the signature.Pass or fail
A match passes DKIM and builds trust in your domain. A missing or failed signature can send the message to spam.
Your receipt from Acme
From billing@acme.com
- Body
- Unchanged
- DKIM
- Pass
Your receipt from Acme
From billing@acme.com
- Body
- Modified
- DKIM
- Fail
Reading a DKIM record
A DKIM record is a TXT record that holds your public key. It lives under a selector, not at the root of your domain.
v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu3QEKyU1fSma0axspqYK5iAj+54lsAg4qRRCnpKK68hawSJ...| Part | What it means |
|---|---|
| s1._domainkey | Where the record lives. s1 is the selector; _domainkey is fixed. |
| v=DKIM1 | The DKIM version. |
| k=rsa | The key type. RSA is the most common. |
| p=MIIBIj... | The public key, base64 encoded. |
The selector lets one domain have several keys: one per sending service, or a new one while you rotate the old one out. Each signature names its selector, so the receiver knows which record to fetch.
acme.com
4 DKIM records
google._domainkey
Google Workspace
zd1._domainkey
Help desk
s2._domainkey
Product email, new key
s1._domainkey
Product email, old key
Reading a DKIM signature
The signature is a header on every message you send. You can see it in the raw source of any email.
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=acme.com; s=s1;
h=from:subject:date:message-id:to;
bh=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN/XKdLCPjaYaY=;
b=GJwP3Qr8KqKKKNT5HL8j3fjXvLEm9KmZs6YdO2KqEqr...| Tag | What it means |
|---|---|
| v=1 | The DKIM version. |
| a=rsa-sha256 | The signing algorithm. |
| d=acme.com | The signing domain. DMARC compares it with the From address. |
| s=s1 | The selector. Points to s1._domainkey.acme.com. |
| h=from:subject... | The headers covered by the signature. |
| bh=frcCV1... | A hash of the message body. |
| b=GJwP3Q... | The signature itself. |
Why DKIM matters
Stops spoofing
Nobody can produce a valid signature for your domain without your private key.Helps you reach the inbox
Gmail, Outlook and Yahoo use a valid signature as a trust signal.Protects your brand
Phishing that uses your domain is easier for inboxes to catch.Needed for DMARC
DMARC builds on DKIM and SPF results.
DKIM vs SPF
Both are authentication checks, but they look at different things. Use both: each covers a case the other misses.
DKIM
- Cryptographic signature in the headers
- Survives forwarding if the content is unchanged
- TXT record at selector._domainkey
- Counts toward DMARC
SPF
- IP address compared with a DNS list
- Breaks on forwarding, because the server changes
- TXT record at the root domain
- Counts toward DMARC
SPF catches mail from servers you never listed; DKIM keeps forwarded mail authenticated where SPF breaks. Read the SPF guide for the other half.
How to set up DKIM
Generate a key pair
Most email providers create the keys for you when you add a domain. Use 2048-bit keys where you can.Publish the public key
Add the record your provider gives you at selector._domainkey.yourdomain.com. Some providers, Plunk included, give you CNAME records that point to keys they host, so they can rotate them for you.Sign outgoing email
Your provider signs every message with the private key once the record is in place.Check it
Look up your selector with the DKIM checker to confirm the key is published and valid.
How to test DKIM
Send yourself a test and open the original
In Gmail, open the message, click the three-dot menu and choose Show original. The summary at the top says whether DKIM passed.Read the headers
The Authentication-Results header shows the verdict per check. Paste raw headers into the email header analyzer to read them more easily.Authentication-Results: mx.google.com; dkim=pass header.i=@acme.com header.s=s1 header.b=GJwP3Qr8; spf=pass (google.com: domain of billing@acme.com designates 54.240.8.1 as permitted sender); dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=acme.comQuery DNS
Confirm the public key is published under the right selector.dig TXT s1._domainkey.acme.com
Original message
- From
- Acme <billing@acme.com>
- Subject
- Your receipt from Acme
- SPF
- Passwith IP 54.240.8.1
- DKIM
- Passwith domain acme.com
- DMARC
- Pass
If DKIM fails, check that:
- The record uses the selector your provider signs with.
- Your DNS provider has not truncated the key. Long keys sometimes need to be split into several strings.
- DNS has propagated, which can take up to 48 hours.
- Your email service signs with the private key that matches the published record.
Best practices
Use 2048-bit keys
1024-bit keys still work, but Gmail and others recommend 2048.Set up SPF and DMARC too
The three work together. DKIM alone does not tell inboxes what to do with forged mail.Monitor results
Check that signatures keep passing, especially after DNS or provider changes.Rotate keys every 6 to 12 months
Publish the new selector before you switch, and remove the old one after.
Share your private key
Treat it like a password. Anyone who has it can sign as you.Reuse a key across domains
Give each domain its own key pair.