Enable DKIM signing for a Microsoft 365 custom domain: get the selector1 and selector2 CNAME values, publish them, turn on signing in the Defender portal or with Set-DkimSigningConfig, and rotate to 2048-bit keys.
Home › Guides › DKIM for Microsoft 365
Last updated 16 October 2026
Get-DkimSigningConfig.selector1._domainkey and CNAME selector2._domainkey pointing at those exact values.Set-DkimSigningConfig -Identity contoso.com -Enabled $true.dkim=pass with d=contoso.com.Your *.onmicrosoft.com domain is already signed automatically. Custom domains are not signed with an aligned key until you do the steps below, and DMARC needs that aligned signature.
Microsoft generates two key pairs per custom domain and keeps the private keys. You don't publish the public key as a TXT record yourself. Instead you publish two CNAME records that point to keys Microsoft hosts, so Microsoft can rotate keys without you editing DNS again. Only one selector signs at a time; the other is used after the next key rotation. That's why you need both CNAMEs.
Get-AcceptedDomain lists it.Install-Module ExchangeOnlineManagement, then Connect-ExchangeOnline.https://security.microsoft.com/authentication?viewid=DKIM.Get-DkimSigningConfig | Format-List Name,Enabled,Status,Selector1CNAME,Selector2CNAME
If your domain isn't listed, create its keys first, choosing 2048-bit (Microsoft's documented default for -KeySize is 1024):
New-DkimSigningConfig -DomainName contoso.com -Enabled $false -KeySize 2048
Run Get-DkimSigningConfig again. The domain should show Enabled: False and Status: CnameMissing, plus the two SelectorNCNAME values.
Microsoft changed the target format in May 2025. Domains added since then get the new format; older custom domains keep the old one. Both are valid, but the two formats can't be mixed for the same selector.
New format (newer custom domains):
selector1._domainkey CNAME selector1-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft selector2._domainkey CNAME selector2-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft
Old format (existing custom domains):
selector1._domainkey CNAME selector1-contoso-com._domainkey.contoso.onmicrosoft.com selector2._domainkey CNAME selector2-contoso-com._domainkey.contoso.onmicrosoft.com
contoso-com is your custom domain with dots replaced by dashes (marketing.contoso.com becomes marketing-contoso-com).contoso (after _domainkey.) is the prefix of your initial *.onmicrosoft.com domain, not your custom domain.n in n-v1 is a partition letter Microsoft assigns (for example n or r). You can't predict it. Two domains in the same tenant can get different letters.The values above are illustrations. Always paste the exact Selector1CNAME / Selector2CNAME values from your tenant.
selector1._domainkey and selector2._domainkey. Most DNS hosts add your domain automatically, so don't type selector1._domainkey.contoso.com or you'll end up with selector1._domainkey.contoso.com.contoso.com.Check that both names resolve with the DNS Lookup tool (type CNAME) and the DNS Propagation Checker. From Windows: nslookup -type=CNAME selector1._domainkey.contoso.com. To inspect the public key behind the CNAME, look up the TXT record of selector1._domainkey.contoso.com and paste it into the DKIM Record Explainer, which shows the key type and size.
Portal: after a few minutes (sometimes longer while DNS propagates), go back to the domain's flyout on the DKIM tab and turn on Sign messages for this domain with DKIM signatures. Once Microsoft sees the CNAMEs, the status changes to Signing DKIM signatures for this domain.
PowerShell:
Set-DkimSigningConfig -Identity contoso.com -Enabled $true Get-DkimSigningConfig -Identity contoso.com | Format-List Name,Enabled,Status
You want Enabled: True and Status: Valid. If the CNAMEs aren't detected yet, the command fails and prints the values it expects. Compare them with DNS character by character (dots, dashes and underscores are easy to get wrong), wait, and try again.
DKIM-Signature, look for d=contoso.com and s=selector1 (or selector2). In Authentication-Results, look for dkim=pass with header.d=contoso.com (or header.i=@contoso.com).Older Microsoft 365 domains were often set up with 1024-bit keys. To check:
Get-DkimSigningConfig -Identity contoso.com | Format-List Selector1KeySize,Selector2KeySize,KeyCreationTime,RotateOnDate,SelectorBeforeRotateOnDate,SelectorAfterRotateOnDate
Rotate to a new 2048-bit key:
Rotate-DkimSigningConfig -Identity contoso.com -KeySize 2048
RotateOnDate. Until then the current key keeps signing, and you can't start another rotation.*.onmicrosoft.com key automatically.d= your domain (or the subdomain you send from), or DMARC won't count it as aligned.Get-DkimSigningConfig output.selector2._domainkey CNAME is missing.d=) doesn't align with the From domain. This is typical of third-party services signing with their own domain.Next, publish a DMARC record so receivers know what to do with mail that fails both SPF and DKIM.
Inspect keys with the DKIM Record Explainer, confirm the CNAMEs with the DNS Lookup and DNS Propagation Checker, read test headers in the Email Header Analyzer, and find a domain's tenant with the M365 Tenant Lookup. Related guides: SPF for Microsoft 365 and DMARC for Microsoft 365.
Two CNAMEs: selector1._domainkey and selector2._domainkey. Custom domains added since May 2025 point to targets like selector1-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft; older domains use selector1-contoso-com._domainkey.contoso.onmicrosoft.com. Copy the exact values from the Defender portal or Get-DkimSigningConfig.
Microsoft keeps the private keys and hosts the public keys. The CNAMEs point to those keys, so Microsoft can rotate them without you changing DNS. A TXT record with a pasted key is not supported for Microsoft 365 signing.
Connect-ExchangeOnline, run Get-DkimSigningConfig to read the selector CNAME values (or New-DkimSigningConfig -DomainName contoso.com -Enabled $false -KeySize 2048 if the domain is not listed), publish both CNAMEs, then run Set-DkimSigningConfig -Identity contoso.com -Enabled $true and confirm Status is Valid.
Run Rotate-DkimSigningConfig -Identity contoso.com -KeySize 2048. The new key starts signing after about four days (96 hours). The size applies to the newly active selector, so rotate again after the first rotation completes to move the other selector to 2048 bits.
Mail sent between users in the same organization is not DKIM signed, so test by sending to an outside mailbox. If outside mail is still unsigned, check that the domain status is Valid in Get-DkimSigningConfig and that both CNAMEs resolve publicly.
Runbooks, checklists and helpdesk templates: IT Admin Packs on Gumroad.