Set Up DKIM and DMARC for Exchange Online Custom Domains
SPF, DKIM and DMARC together let receiving mail systems check that mail claiming to come from your domain really did. Microsoft 365 signs mail from your *.onmicrosoft.com domain automatically, but no DKIM signing happens for custom domains until you set it up (DKIM (opens in a new tab)). DMARC then tells receivers what to do when SPF and DKIM don't line up with the From address (DMARC (opens in a new tab)). DKIM alone isn't enough; Microsoft's guidance is to configure all three.
Use it when: you onboard a new tenant or domain, a customer is being spoofed, or a receiving provider starts rejecting or junking your mail.
Before you start
- Domain added to Microsoft 365. You can only DKIM sign with a custom domain or subdomain after it's added to Microsoft 365;
Get-AcceptedDomainconfirms it (Use Exchange Online PowerShell (opens in a new tab)). - DNS access at the registrar or DNS host. There are no Microsoft 365 portals or cmdlets for custom-domain DMARC records; you create them in DNS (DMARC (opens in a new tab)).
- Permissions: the Exchange Online cmdlet pages say you need permissions assigned before you can run them and link to a lookup procedure (Get-DkimSigningConfig (opens in a new tab)). The DKIM diagnostic test in Microsoft 365 help needs Global Administrator (Verify DKIM signing (opens in a new tab)).
- License: no add-on is needed for these steps. Learn presents them for any Microsoft 365 organization, and the inbound DMARC handling settings are part of the built-in security features for all cloud mailboxes (DMARC for inbound mail (opens in a new tab)).
Step 1: SPF first
Each domain or subdomain that sends mail needs exactly one SPF TXT record; multiple records cause permerror. Most Microsoft 365 organizations need include:spf.protection.outlook.com. Microsoft recommends -all (hard fail) when you also deploy DKIM and DMARC, and the record must stay under 10 DNS lookups (SPF (opens in a new tab)). Cloud-only example:
v=spf1 include:spf.protection.outlook.com -all
Step 2: DKIM for each custom domain
- In the Defender portal go to Email & collaboration > Policies & rules > Threat policies > Email authentication settings > DKIM (or
https://security.microsoft.com/authentication?viewid=DKIM). The domain should show Toggle: Disabled and Status: NoDKIMKeys (Enable DKIM (opens in a new tab)). - Try to switch the toggle on. A Client error dialog appears (expected). Select OK, and the status becomes CnameMissing.
- Open the domain's details flyout and copy the two values under Publish CNAMEs.
- At your DNS host, create both CNAMEs. Hostnames are always
selector1._domainkeyandselector2._domainkey. Always copy the targets from the portal or PowerShell: domains added since May 2025 use a newer format (selector1-contoso-com._domainkey.contoso.n-v1.dkim.mail.microsoft, with a dynamic partition character), while older domains useselector1-contoso-com._domainkey.contoso.onmicrosoft.com. The two formats can't coexist for the same selector (Syntax for DKIM CNAME records (opens in a new tab)). Use a TTL of at least 3600 seconds (TTL set too low (opens in a new tab)). - After Microsoft 365 detects the records (minutes, sometimes longer), go back to the flyout and turn on Sign messages for this domain with DKIM signatures. Success shows Status: Signing DKIM signatures for this domain, and Rotate DKIM keys becomes available.
- Repeat for every subdomain that sends mail; each needs its own DKIM configuration (Subdomain considerations (opens in a new tab)).
Step 3: DMARC, gradually
Record syntax: hostname _dmarc, value v=DMARC1; p=<none|quarantine|reject>; pct=<0-100>; rua=mailto:<address>; ruf=mailto:<address>. If you leave out pct, it defaults to 100 (Syntax for DMARC TXT records (opens in a new tab)). Microsoft's rollout (Set up DMARC for active custom domains (opens in a new tab)):
- Start with a low-volume domain or subdomain at
p=noneand read the aggregate (rua) reports to find every legitimate sender. - Move to
p=quarantine, optionally steppingpctthrough 10, 25, 50, 75 and 100. - Move to
p=reject. - Repeat for the remaining subdomains and do the parent domain last. Subdomains inherit the parent's DMARC record unless they have their own.
Example starting record: v=DMARC1; p=none; pct=100; rua=mailto:rua@contoso.com
Parked domains (registered but never used for mail): publish v=DMARC1; p=reject; and no DKIM records. This includes the *.onmicrosoft.com domain if you don't send from it. Add its DMARC record in the Microsoft 365 admin center under Settings > Domains > [onmicrosoft domain] > DNS records > Add record (TXT, name _dmarc) (Parked domains (opens in a new tab), onmicrosoft.com DMARC (opens in a new tab)).
Report-first PowerShell
Read-only checks in Exchange Online PowerShell. Resolve-DnsName runs on Windows. These commands come from Learn's DKIM and DMARC troubleshooting sections (DMARC PowerShell commands (opens in a new tab), DKIM (opens in a new tab)).
Connect-ExchangeOnline
# DKIM status and the exact CNAME targets for every domain
Get-DkimSigningConfig | Format-List Name, Enabled, Status, Selector1CNAME, Selector2CNAME
# Key age and rotation details for one domain
Get-DkimSigningConfig -Identity contoso.com |
Format-List KeyCreationTime, RotateOnDate, SelectorBeforeRotateOnDate, SelectorAfterRotateOnDate
# What's published in DNS
Resolve-DnsName -Name "_dmarc.contoso.com" -Type TXT | Select-Object -ExpandProperty Strings
Resolve-DnsName -Name "contoso.com" -Type TXT | Where-Object { $_.Strings -like "v=spf1*" }
# How Microsoft 365 treats inbound mail that fails the sender's DMARC
Get-AntiPhishPolicy | Format-List Name, HonorDmarcPolicy, DmarcQuarantineAction, DmarcRejectAction
Leave changes (New-DkimSigningConfig, Set-DkimSigningConfig, Rotate-DkimSigningConfig) to a reviewed change window.
Gotchas
- Copy CNAME values, don't build them by hand. Values in docs and blogs are illustrations, and the newer format includes a partition character only Microsoft 365 knows (Syntax (opens in a new tab)). Common mistakes Learn lists: wrong hostname format, a missing selector2, a TXT record instead of a CNAME, and a domain mismatch or a missing or extra trailing dot in the target (Troubleshoot DKIM DNS (opens in a new tab)).
- DKIM only helps DMARC when it aligns. The DKIM signing domain (
d=) must align with the From domain to pass DMARC (DKIM (opens in a new tab)). Third-party senders (marketing, ticketing) need their own SPF and DKIM for your domain, or should send from a subdomain. - Key rotation takes four days. After
Rotate-DkimSigningConfigor Rotate DKIM keys, the new key starts signing after 96 hours. There's no automatic rotation for the*.onmicrosoft.comdomain (Rotate DKIM keys (opens in a new tab)). - Failing outbound mail with quarantine or reject goes through the high-risk delivery pool, and there's no override (Syntax tip (opens in a new tab)).
- Microsoft 365 never sends forensic (
ruf) reports, and it only sends aggregate reports when your MX points directly to Microsoft 365 (DMARC for inbound mail (opens in a new tab)). Expectruareports from other providers, not a full picture. - Same-domain test mail isn't signed. DKIM is omitted when sender and recipient are in the same domain, so test to an outside mailbox. Don't use AOL for DKIM tests, because it may skip the check if SPF passes (Verify DKIM signing (opens in a new tab)).
Check it worked
- Send from the domain to an external mailbox and open the headers: DKIM-Signature shows
d=yourdomainwiths=selector1orselector2, and Authentication-Results showsdkim=pass,spf=passanddmarc=pass(Verify DKIM signing (opens in a new tab)). Get-DkimSigningConfigshowsEnabled: Truefor every sending domain.- Aggregate reports show your legitimate sources passing before you tighten the policy.
Roll back
Lower DMARC back to p=quarantine or p=none in DNS. DKIM signing for a custom domain can be turned off in the domain's flyout on the DKIM tab or with Set-DkimSigningConfig -Enabled $false (Disable DKIM signing (opens in a new tab)).
Related on EntraReady: Block legacy authentication, Guest access cleanup, Investigate risky users and sign-ins.
← All GuidesIs this still accurate?
Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.