
DKIM setup takes four steps: list every service that sends mail as your domain, turn on signing in each one, publish the public key it gives you as a TXT or CNAME record at selector._domainkey.yourdomain, then send a test and read the header. Each service needs its own key and selector. DNS changes can take up to 48 hours to show.
DKIM is DomainKeys Identified Mail, a standard that lets a sending server sign each message with a private key so the receiver can verify it against a public key in your DNS. This page is the procedure. For how the signature works and how it ties to SPF and DMARC, read our guide to SPF, DKIM and DMARC.
What do you need before you start?
You need three things: a list of every system that sends mail with your domain in the From address, admin access to each of those systems, and access to the DNS zone of the domain. The list matters most, because one unsigned sender is enough to produce failures later.
A DKIM key belongs to one sending service, not to the domain as a whole. Your mailbox platform, your marketing platform, your help desk and your invoicing tool each sign with a key of their own. Each key sits in DNS under a different name, called a selector.
| Sender | Typical example | Who creates the key pair | What you publish |
|---|---|---|---|
| Mailbox platform | Google Workspace, Microsoft 365 | The platform | 1 TXT record, or 2 CNAME records |
| Marketing or CRM platform | Klaviyo, a newsletter tool | The platform | CNAME records that point to keys the platform hosts |
| Transactional service | SendGrid, an API mail service | The service | CNAME or TXT records |
| Your own mail server | Postfix with a signing filter | You | 1 TXT record with the public key |
| Devices and apps on a relay | A printer, a web form | The SMTP relay they send through | Whatever that relay asks for |
Write the list down with one row per sender, the selector it will use and the date you turned signing on. That sheet is the reference for every later change.
How does DKIM setup work, step by step?
The steps are the same on every platform: create a key pair, publish the public half in DNS under a selector, turn on signing, and verify. Only the screens and the record type change from one service to the next.
- Choose the signing domain. This is the
d=value in the signature. Use the domain in your From address, or a subdomain of it, so the signature can count toward DMARC. - Create the key pair. The service does this for you in most cases. The private key stays with the signer and never goes into DNS.
- Note the selector. The selector is a short label, the
s=value, that tells the receiver which key to fetch. Google Workspace usesgoogleby default and Microsoft 365 usesselector1andselector2. - Publish the record. Add the TXT or CNAME record the service shows you, at the exact host name it gives.
- Turn on signing. Most platforms have a separate switch that you flip after the record is visible.
- Verify with a real message. Send to an outside mailbox and read the result in the header.
RFC 6376, the DKIM standard published in September 2011, fixes where the key lives. Section 3.6.2.1 says every key is stored under a _domainkey subdomain, so a signature with d=example.com and s=mail2026 sends the receiver to this name:
mail2026._domainkey.example.com. 3600 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...IDAQAB"
The value is cut short here for display. A DKIM record is a list of tags, and RFC 6376 section 3.6.1 marks only one of them as required:
| Tag | Meaning | Status in RFC 6376 |
|---|---|---|
v= |
Version. The value is DKIM1 and it comes first when present |
Recommended |
k= |
Key type. The default is rsa |
Optional |
p= |
The public key, in base64. An empty value means the key has been revoked | Required |
t= |
Flags, such as y for a domain that is testing DKIM |
Optional |
h=, s=, n= |
Accepted hash algorithms, service type, and notes | Optional |
If you run your own mail server, you create the pair yourself. These two commands produce a 2048-bit private key and print the public half as the single line that goes after p=:
openssl genrsa -out dkim-private.pem 2048
openssl rsa -in dkim-private.pem -pubout -outform der | openssl base64 -A
We ran both commands while writing this page. The public half of a 2048-bit key came to 392 characters, and that length matters for the TXT record, as the section on key length explains.
How do you set up DKIM in Google Workspace?
In Google Workspace you generate the key in the Admin console, publish one TXT record, wait, and then start authentication. As of December 4, 2026, these are the steps on Google's page Set up DKIM.
- Sign in as a super administrator. If Gmail was turned on recently, Google says to wait 24 to 72 hours before you generate a key.
- In the Admin console, go to Menu, then Apps, then Google Workspace, then Gmail, and click Authenticate email.
- Pick the domain and click Generate New Record.
- Choose the key length. Google says to select 2048 if your domain provider supports it, and 1024 if it does not.
- Keep the prefix selector
google, unless the domain already has a key under that name. - Copy the host name, which is
google._domainkey, and the TXT value, which startsv=DKIM1; k=rsa; p=. - Add the TXT record at your DNS host.
- Go back to the same screen and click Start authentication.
Two details on that page save time. Google says it can take up to 48 hours after you add the key for authentication to start working, and it tells you not to click the start button before the record is in place. When it works, the status changes to Authenticating email with DKIM.
Each domain in the account needs its own key. If you have five domains or aliases that send mail, you repeat the steps five times, once per domain in the Selected domain menu.
How do you set up DKIM in Microsoft 365?
In Microsoft 365 you publish two CNAME records that point to keys Microsoft hosts, then turn signing on in the Defender portal. As of December 4, 2026, the steps below are on the Microsoft Learn page Set up DKIM to sign mail from your Microsoft 365 domain.
The first fact to know is the default. Mail from the onmicrosoft.com domain that came with the account is signed automatically. For your own domain, the page says, "Currently, no DKIM signing occurs for outbound mail from custom domains."
- Open the DKIM tab of Email authentication settings in the Defender portal, under Email & collaboration, Policies & rules, Threat policies.
- Select the custom domain and slide the toggle to Enabled. A dialog shows the two CNAME values, and the status becomes CnameMissing.
- Copy both values from Publish CNAMEs in the domain's details.
- Create both records at your DNS host.
- Return to the domain and turn on Sign messages for this domain with DKIM signatures.
- Check that the status reads Signing DKIM signatures for this domain.
The host names are the same for every organization. The targets are not, and Microsoft changed their format for new custom domains in May 2025:
| Record | Host name | Points to |
|---|---|---|
| Selector 1 | selector1._domainkey |
An older domain: selector1-example-com._domainkey.example.onmicrosoft.com |
| Selector 2 | selector2._domainkey |
An older domain: selector2-example-com._domainkey.example.onmicrosoft.com |
| Either, new format | Same host names | A target that ends in -v1.dkim.mail.microsoft, with a partition letter that Microsoft assigns |
Do not build the target by hand. Copy it from the portal, or read it with the PowerShell command Get-DkimSigningConfig. Microsoft's page says the old and new formats cannot coexist for the same selector.
The same page lists the errors that stall this setup. A TXT record in place of the CNAME is not supported. Entering the full domain in the host field doubles the domain. On Cloudflare the record has to be set to DNS only, with the proxy off.
One more point on key size. Microsoft's PowerShell reference on that page gives 1024 as the default of the KeySize parameter and 2048 as the other value. If you want 2048, check what your domain has before you assume it.
How do you set up DKIM on a sending platform?
On a marketing or transactional platform you authenticate your domain in the platform's settings and publish the records it generates, which are usually CNAME records. The platform keeps the keys and you delegate the names to it. Until you do this, the platform signs with a domain of its own, and that signature cannot align with your From address.
Two examples show the pattern. Both describe the vendor's pages as we read them on December 4, 2026:
| Platform | What its documentation asks you to publish | Wait it states |
|---|---|---|
| SendGrid, with automated security on | 4 records: 1 CNAME for the sending domain that supports SPF and DKIM, 2 CNAME records for link branding, 1 TXT record for DMARC. Source: domain authentication | Up to 48 hours |
| Klaviyo, static routing | 3 CNAME records, 2 of them for the selectors km1 and km2, plus 1 TXT record. Source: branded sending domain |
Up to 48 hours |
| Klaviyo, dynamic routing | 4 NS records that delegate a sending subdomain, plus 1 TXT record | Up to 48 hours |
Klaviyo's article says that without a branded domain, most accounts send from a shared domain and the message shows a via label beside the sender. That label is the visible sign that the DKIM signature belongs to the platform and not to you.
Use a subdomain for platforms you do not run yourself. Microsoft's DKIM page recommends this for bulk email services, with marketing.contoso.com as its example, so that problems with that mail do not affect the reputation of your main domain. Each subdomain then gets its own DKIM configuration.
A CNAME and a TXT record lead to the same key in the end. The difference is who can change it:
| TXT record | CNAME record | |
|---|---|---|
| What sits in your DNS | The public key itself | A pointer to a name in the provider's zone |
| Who replaces the key | You, by editing DNS | The provider, with no change on your side |
| Risk | A stale or cut-off key | The provider's target name changing or being removed |
| Seen on | Google Workspace, your own server | Microsoft 365, most sending platforms |
Which key length should you use, and why does a 2048-bit key get split?
Use a 2048-bit RSA key wherever the service and your DNS host allow it. RFC 8301, published in January 2018, says signers must use RSA keys of at least 1024 bits and should use at least 2048 bits.
The same RFC covers the receiving side. Verifiers must be able to validate keys from 1024 to 4096 bits, and must not treat a signature from a key shorter than 1024 bits as valid. It also retires the older algorithm: rsa-sha1 must not be used, which leaves rsa-sha256.
A 2048-bit key is too long for one TXT string. RFC 1035 defines a character string as one length octet followed by the characters, up to 256 octets in all, so one string holds 255 characters. A 2048-bit public key is 392 characters in base64 before the tags are added.
The fix is in the standards. A TXT record can hold more than one string, and RFC 6376 section 3.6.2.2 says the strings are joined before use with no whitespace between them. A split record looks like this in a zone file:
mail2026._domainkey.example.com. 3600 IN TXT ( "v=DKIM1; k=rsa; "
"p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...first part..."
"...second part...IDAQAB" )
Most DNS control panels split a long value for you when you paste it as one line. Some do not accept it at all. Google's setup page notes that some providers limit TXT record length, which is why it offers 1024 as the fallback.
| Key length | Base64 length of the public key | Fits in one TXT string | Standing in RFC 8301 |
|---|---|---|---|
| Under 1024 bits | Shorter | Yes | Verifiers must not accept it |
| 1024 bits | 216 characters | Yes | The minimum for signers |
| 2048 bits | 392 characters | No, it needs 2 strings | The recommended size |
The two base64 lengths are our own measurement with the commands shown earlier. Never split the key by adding a space or a line break inside a pair of quotes. That changes the key, and every signature then fails.
How do you check that signing works?
Check two things in order: that the DKIM key is visible in DNS, and that a real message arrives with a passing signature. The first proves the record, and only the second proves the whole chain.
Query the record with dig, using the selector and domain from your notes:
$ dig +short TXT mail2026._domainkey.example.com
"v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..." "...IDAQAB"
An empty answer means the record is missing, misnamed or not yet visible. Two quoted strings are normal for a 2048-bit key. You can run the same lookup in a browser with our DKIM checker.
Then send a message to a mailbox outside your organization and open the original. Google's page says you cannot verify by sending to yourself. Microsoft's page says a message between two of your own domains may carry no signature at all.
The lines to find look like this. They are an illustration in the usual format, with example names, not a captured header:
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=mail2026;
h=from:to:subject:date:message-id; bh=...; b=...
Authentication-Results: mx.receiver.example;
dkim=pass header.i=@example.com header.s=mail2026
Read three values. dkim=pass says the signature verified. d= should be your domain or a subdomain of it, not the platform's domain. s= should be the DKIM selector you published.
A pass with the wrong d= is the result people miss. The DKIM signature is valid, but it belongs to the platform, so DMARC cannot use it. Our article on DMARC fail covers that case.
What do Gmail and Yahoo ask of a DKIM signature?
Gmail and Yahoo both accept SPF or DKIM from small senders and ask bulk senders for both, and both set 1024 bits as the shortest key. As of December 4, 2026, these are the rules on each provider's own page.
| Rule | Yahoo | |
|---|---|---|
| All senders | SPF or DKIM for the sending domain | SPF or DKIM at a minimum |
| Bulk senders | SPF and DKIM, plus DMARC. Bulk means more than 5,000 messages a day | Both SPF and DKIM, and DMARC must pass |
| Shortest key | 1024 bits for mail to personal Gmail accounts. 2048 recommended where the domain provider supports it | 1024 bits |
| Alignment | The From domain must align with the SPF domain or the DKIM domain, for bulk senders | The From domain must align with the SPF or DKIM domain. Relaxed alignment is accepted |
| Source | Email sender guidelines | Sender Best Practices |
Google's page says its requirements took effect on February 1, 2024. Yahoo's page adds that each DKIM domain carries its own reputation, and it asks senders to enroll their DKIM domains in its complaint feedback loop.
These rules are a floor for being accepted. Meeting them does not decide where a message is filed, because that also depends on complaints and sending history. For Gmail, Google Postmaster Tools shows whether your signed mail is passing.
When and how should you rotate a key?
Rotate a key on a schedule you can keep, and at once if the private key may have been exposed. RFC 6376 gives the method and no fixed interval. Microsoft's page compares it to changing passwords and names no interval either.
Selectors are what make rotation safe. RFC 6376 section 3.1 says they let a domain replace public keys routinely, because a new key gets a new name and the old one stays in place. The sequence is:
- Create a new key pair with a new selector, for example
mail2027. - Publish the new record and confirm it with
dig. - Switch the signer to the new selector.
- Leave the old record in DNS while mail signed with it is still in transit. RFC 6376 section 5.2 calls for "a reasonable validation interval" and gives no number.
- Remove the old record, or publish it with an empty
p=value to mark it revoked.
On Microsoft 365 the platform does the switch for you. You click Rotate DKIM keys, and the page says it takes four days, or 96 hours, for the new private key to start signing. A second rotation cannot start while the first is in progress.
Where the records are CNAMEs to a sending platform, the platform replaces the key behind the pointer. Your DNS does not change. Whether and how often a given platform does this is for that platform to state, and we give no figure here.
Which mistakes break a new setup?
Most broken setups come from the DNS entry and not from the key. The record is at the wrong name, has the wrong type, or holds a damaged value.
| Mistake | What you see | Repair |
|---|---|---|
| Full domain typed in a host field that adds it for you | The record lands at selector._domainkey.example.com.example.com |
Enter only the part before the domain |
| TXT record where the service asked for a CNAME | The platform never verifies the domain | Delete it and add the CNAME |
| CNAME behind a proxy at the DNS host | The lookup returns the proxy, not the key | Set the record to DNS only |
| Key pasted with a break or a space inside the quotes | dkim=fail on every message |
Paste again as one line and compare lengths |
| Signing switched on before the record is visible | Failures for the first hours | Wait, confirm with dig, then turn it on |
| Record published and signing never turned on | No DKIM-Signature header at all |
Flip the switch in the platform |
| One service set up, the others forgotten | Passes for some mail, failures for the rest | Go back to the inventory |
| Signing with the platform's default domain | dkim=pass with the wrong d= |
Finish the custom domain steps |
The first three rows are on Microsoft's troubleshooting list for its own setup. The rest follow from how the record is read: RFC 6376 section 6.1.2 says a verifier ignores a key record that is malformed.
DKIM is one record among three. If you edit SPF in the same session, keep it to a single record, as multiple SPF records explains.
How we set up DKIM on a client domain
We start from the mail and not from the DNS zone, because the zone shows what someone intended and the mail shows what is sending. The order below is the one we follow.
- We pull the senders from DMARC reports where they exist, and from a sample of real messages where they do not. Every source that uses the domain goes on the inventory.
- We check each sender's current signature. We read
d=,s=and the result in a delivered message, and mark it as aligned, signed by the platform, or unsigned. - We set up the mailbox platform first, with a 2048-bit key where the DNS host takes it.
- We move each outside platform to a subdomain and publish its records, one platform at a time.
- We verify with a message per sender to mailboxes at Gmail and Microsoft, and keep the headers.
- We record the selector, key length and date for each sender, so the next rotation starts from facts.
The case we check for first is the last row of the mistakes table, not a broken key. The domain has DKIM turned on for the mailbox platform, and other tools still sign as themselves.
On one audit of 31 domains and 11 sending services in our case studies, domains passing authentication checks went from 63% to 100%. That work covered SPF, DKIM and DMARC together, so the figure is not a DKIM result alone.
To see which selectors and records your domain publishes today, run the free domain check.
Drafted with AI assistance from our own records and client work, then reviewed and approved by Kunal Arora. See our editorial policy.