DKIM Explained - DNS Keys, Selectors, and Email Signatures
Learn how DKIM signs outbound email, where DKIM public keys live in DNS, how selectors work, and how to rotate DKIM keys safely.
TL;DR
DKIM adds a cryptographic signature to outbound email. The sender signs selected headers and body content with a private key; receivers fetch the public key from DNS at selector._domainkey.example.com and verify the signature. DKIM survives forwarding better than SPF and is one of the two authentication signals DMARC can use for alignment. Publish provider-generated DKIM TXT records, use 2048-bit keys where supported, and rotate selectors without deleting old keys too early.
What you'll learn
- Understand how DKIM signatures are verified
- Publish DKIM public keys in DNS
- Use selectors for key rotation and multiple providers
- Diagnose common DKIM failures
DKIM (DomainKeys Identified Mail) lets a receiving mail server verify that a message was signed by a domain and was not materially changed in transit.
The private key stays with the sending mail system. The public key is published in DNS as a TXT record. Receivers use that public key to verify the DKIM-Signature header on the message.
DKIM works with SPF and DMARC. DMARC can pass when DKIM passes and aligns with the visible From domain.
How DKIM Works
- Your sending platform creates a private/public key pair.
- You publish the public key in DNS.
- The sender signs outbound messages with the private key.
- The signature includes a selector and domain.
- The receiver looks up
selector._domainkey.domain. - The receiver verifies the signature with the DNS public key.
If verification succeeds, DKIM passes.
DKIM DNS Record
Example:
selector1._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqh..."Important tags:
| Tag | Meaning |
|---|---|
v=DKIM1 | DKIM version marker. |
k=rsa | Key type. RSA is common; some providers support Ed25519. |
p= | Base64 public key. |
t=y | Testing mode. Rare in production. |
t=s | Strict domain matching. |
Selectors
The selector lets a domain publish multiple DKIM keys. The sender chooses the selector in the DKIM-Signature header:
DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=selector1; ...The receiver queries:
selector1._domainkey.example.com TXTSelectors make these workflows possible:
- Separate keys for Google Workspace and a marketing platform
- Zero-downtime key rotation
- Different keys per mail stream
- Emergency revocation of one sender without breaking others
Key Length and TXT Splitting
Use 2048-bit RSA keys where your provider supports them. Long public keys may exceed the 255-byte DNS string limit. In zone-file form, they are split into multiple quoted strings:
selector1._domainkey.example.com. TXT (
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A"
"MIIBCgKCAQEArandomexamplekeymaterial..."
)Resolvers concatenate the strings before the mail server uses the key. DNScale handles long TXT values through the dashboard and API, but raw zone files must preserve correct quoting.
Safe DKIM Rotation
- Generate a new selector at the provider.
- Publish the new DNS TXT record.
- Wait for DNS propagation.
- Enable signing with the new selector.
- Keep the old selector published for at least several days.
- Remove the old selector only after retries and queued mail have drained.
Deleting the old key too early causes DKIM failures for delayed mail.
DNScale Setup
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "selector1._domainkey",
"type": "TXT",
"content": "v=DKIM1; k=rsa; p=MIIBIjANBgkqh...",
"ttl": 3600
}'Validation
dig TXT selector1._domainkey.example.com +shortInspect a received email's headers and confirm:
dkim=passd=example.coms=selector1- DMARC alignment passes if the From domain matches or aligns
Related Guides
Frequently asked questions
- Where is a DKIM record published?
- A DKIM public key is published as a TXT record at selector._domainkey.yourdomain. The selector is named by the sending system in the DKIM-Signature header.
- Who generates DKIM keys?
- Usually your email provider. Google Workspace, Microsoft 365, SES, Postmark, SendGrid, and similar platforms generate the private/public key pair. They keep the private key and give you the DNS TXT record for the public key.
- Can I have multiple DKIM records?
- Yes. DKIM supports multiple selectors. Each selector is a different DNS name, so different providers and key rotations can coexist safely.
- Why does DKIM fail?
- Common causes are a missing DNS key, broken TXT splitting, wrong selector, message modification after signing, expired provider configuration, or a key that was deleted before old mail stopped being retried.
- Does DKIM replace SPF?
- No. DKIM and SPF authenticate different parts of the mail flow. DKIM is usually more robust through forwarding; SPF is still useful for direct sender authorization. DMARC can pass with aligned DKIM even when SPF fails.
Related guides
MTA-STS and TLS-RPT Guide - Enforce Encrypted Email Delivery
Learn how MTA-STS and TLS-RPT protect inbound SMTP delivery, which DNS records they require, how the HTTPS policy file works, and how to deploy without breaking mail.
SPF Record Explained - Syntax, Examples, and Common Mistakes
Learn how SPF records authorize mail senders, how SPF syntax works, how to avoid the 10-DNS-lookup limit, and how to validate SPF with dig.
DMARC Explained - Policy, Alignment, and Reports
Learn how DMARC uses SPF and DKIM alignment to stop domain spoofing, how p=none/quarantine/reject works, and how to roll out DMARC safely.
Email Security with SPF, DKIM, and DMARC
Learn how to protect your domain from email spoofing using SPF, DKIM, and DMARC records. Step-by-step guide for dashboard and API setup on DNScale.
Ready to manage your DNS with confidence?
DNScale provides anycast DNS hosting with a global network, real-time analytics, and an easy-to-use API.
Start free