SPF, DKIM and DMARC
Set Up SPF, DKIM and DMARC for Microsoft 365
Publish SPF with include:spf.protection.outlook.com, add Microsoft's two DKIM CNAMEs and turn on signing in Defender, then add DMARC and move to enforcement.
On this page
To authenticate Microsoft 365 mail for a custom domain, you need three DNS records plus one switch: an SPF record that includes spf.protection.outlook.com, two DKIM CNAME records that Microsoft generates for you, the Sign messages for this domain with DKIM signatures toggle turned on in the Defender portal, and a DMARC record at _dmarc.example.com. SPF is usually done during tenant setup. DKIM is the step most tenants are missing, and without it your DMARC is relying on SPF alone.
Before you start
You need:
- An admin account that can manage domains in the Microsoft 365 admin center and email authentication settings in the Defender portal.
- Access to your DNS host. If Microsoft 365 manages your DNS, you'll add the records in the admin center; otherwise it's your registrar or DNS provider.
- A list of everything else that sends as your domain: marketing platform, CRM, helpdesk, scanners and copiers that send through 365. DMARC applies to all of it. The sender inventory guide covers how to build that list.
If you only send from the contoso.onmicrosoft.com domain Microsoft created for you, SPF and DKIM are already handled. You still have to add DMARC yourself (see step 3).
Step 1: SPF
SPF lists the servers allowed to send for your domain. (Background: What Is an SPF Record?.) If Microsoft 365 is your only sender, Microsoft's recommended record is:
v=spf1 include:spf.protection.outlook.com -all
Government and sovereign clouds use different includes: GCC High and DoD use include:spf.protection.office365.us, and the 21Vianet-operated service uses include:spf.protection.partner.outlook.cn. Standard commercial and GCC tenants use the one above.
- At your DNS host, find the TXT record on the root of the domain that starts with
v=spf1. The domain setup wizard in 365 asked you to create it, so it's probably there. - If you send through other services too, add their includes to the same record:
v=spf1 include:spf.protection.outlook.com include:spf.esp.example.net -all
- Don't create a second SPF record. Microsoft's docs are explicit that only one SPF record is allowed per domain, and two of them cause a
permerrorfor everything. See Multiple SPF Records to merge them.
Microsoft recommends -all (hard fail) for 365 domains, and explains why: DMARC treats ~all and -all both as failures, but Microsoft 365 effectively ignores the DMARC policy for a ~all failure on a message with no DKIM signature. -all lets DMARC act on that mail.
Two more rules from Microsoft's SPF page:
- Each sending subdomain needs its own SPF record. The record for
contoso.comdoesn't covermarketing.contoso.com. - The 10 DNS lookup limit applies.
include,a,mx,existsandredirecteach count;ip4,ip6andalldon't. Check yours with the SPF analyzer, and see the lookup limit page if you're over.
Step 2: DKIM
DKIM adds a signature to each message that receivers check against a public key in your DNS. For DMARC it's the more important of the two, because it survives forwarding. Background: What Is DKIM?.
Microsoft's current documentation says mail from a custom domain isn't DKIM signed until you set this up. Microsoft 365 uses two selectors, selector1 and selector2, published as CNAME records that point at keys Microsoft hosts. That's what lets Microsoft rotate keys without you touching DNS again.
- Open the Defender portal at Email & collaboration > Policies & rules > Threat policies > Email authentication settings, and select the DKIM tab. (The direct link is
https://security.microsoft.com/authentication?viewid=DKIM.) - Select your custom domain. If the status is NoDKIMKeys, slide the toggle to Enabled. You'll get an error dialog showing the CNAME values. That's expected. Click OK.
- The status changes to CnameMissing. Open the domain's details flyout and copy the two values under Publish CNAMEs.
- At your DNS host, create both CNAME records. For a domain added recently, they look like this (your values will differ; copy them from the portal, don't type them from this page):
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
Older domains use the older format, pointing at selector1-contoso-com._domainkey.contoso.onmicrosoft.com. Either works; use whatever the portal shows you.
- Wait for the records to publish, then return to the flyout and turn on Sign messages for this domain with DKIM signatures. The status should read Signing DKIM signatures for this domain.
Repeat for every custom domain and sending subdomain in the tenant.
If you prefer PowerShell, Get-DkimSigningConfig shows the CNAME values and status, and Set-DkimSigningConfig -Identity contoso.com -Enabled $true turns signing on. Microsoft lists 1024 as the default key size for New-DkimSigningConfig, so pass -KeySize 2048 when creating a config or rotating keys.
Publishing the CNAMEs isn't enough on its own. Plenty of tenants have both records in DNS and signing still switched off. Check that the status in Defender actually says it's signing.
Rotation. You can rotate keys from the domain's flyout (Rotate DKIM keys) or with Rotate-DkimSigningConfig. Microsoft says a rotation takes 96 hours to complete, during which the old key keeps signing.
Step 3: DMARC
DMARC tells receivers what to do with mail that fails both SPF and DKIM for your From domain, and gets you reports on everything sent as you. There's no portal setting for it; it's a TXT record.
- Set up a mailbox or group to receive aggregate reports.
- At your DNS host, create a TXT record on
_dmarcwith a monitoring policy:
v=DMARC1; p=none; rua=mailto:dmarc-reports@contoso.com
The DMARC generator will build one, and DMARC Record Syntax explains the tags.
- Read the reports for a few weeks and fix each legitimate source that fails. How to read DMARC reports covers what to look for.
- Move to
p=quarantineand thenp=reject. Microsoft's own guidance suggests rampingpctthrough 10, 25, 50, 75 and 100, starting with low-volume subdomains and doing the parent domain last. The current DMARC standard, RFC 9989, retiredpctin favor of at=ytest step. Receivers that implementedpctmay keep honoring it for a while, but uset=ywhen you next edit the record. See DMARC Policy for the full rollout.
If you only use the onmicrosoft.com domain, Microsoft says you add DMARC in the Microsoft 365 admin center: Settings > Domains, select the onmicrosoft.com domain, open DNS records, and add a TXT record named _dmarc.
Microsoft's sender requirements for Outlook.com apply to high-volume senders to consumer mailboxes, so if your tenant sends in volume, DMARC is a requirement there too.
How to confirm it's working
Send a message from a 365 mailbox to an external account, such as a personal Gmail address, and view the original headers. You want SPF, DKIM and DMARC all passing, and the DKIM signature should have d=contoso.com (your domain) with s=selector1 or s=selector2. Paste the headers into the header analyzer if you'd rather not read them raw, or run the domain through the email checker to see what's published.
Keeping it working
- Add every new sending service to SPF or, better, set up DKIM on your domain for it before it goes live.
- Watch DMARC reports after any change.
- If outbound mail is being refused by Microsoft itself rather than by recipients, that's a different problem. See Why Is Microsoft 365 Blocking My Outbound Email? and 550 5.7.509.
When to get help
If the reports show sources you can't account for, or you're about to move a busy domain to p=reject and want a second set of eyes, it's worth bringing someone in. Get in touch.
FAQ
Does Microsoft 365 sign my email with DKIM automatically?
Only for the onmicrosoft.com domain. For your own custom domain, Microsoft's documentation says you need to publish the two CNAME records and turn signing on in Defender.
Should I use -all or ~all with Microsoft 365?
Microsoft recommends -all, because Microsoft 365 effectively ignores the DMARC policy for ~all failures on unsigned messages. Make sure every legitimate sender is in the record first.
Why does the DKIM toggle give me an error?
The first time you enable it, the error is how the portal shows you the CNAME values to publish. Once the records are in DNS, the toggle works.
How long does it take before I can turn DKIM signing on?
Microsoft says detecting the new CNAME records can take a few minutes or longer. If the toggle still fails after a day, check the published records against the values in the portal.
Sources
- Microsoft Learn: Set up SPF to identify valid email sources for your Microsoft 365 domain
- Microsoft Learn: Set up DKIM to sign mail from your Microsoft 365 domain
- Microsoft Learn: Set up DMARC to validate the From address domain in Microsoft 365
- RFC 9989: Domain-Based Message Authentication, Reporting, and Conformance (DMARC)
Related guides
- Authenticating Every Tool That Sends as Your Domain (Sender Inventory)List every service that sends mail as your domain, then give each one SPF coverage and DKIM signing on your domain so all of them pass DMARC.
- BIMI Logo Not Showing: Troubleshooting ChecklistA BIMI logo usually fails to show because DMARC isn't at enforcement, the SVG or certificate is wrong, or the provider has chosen not to display it.
- DKIM Fail: Body Hash Did Not Verify, Signature Failed and Other CausesDKIM fails when the message changed after signing (body hash did not verify), the signed headers changed, or the receiver can't find a matching public key.
- DMARC Fail: Why DMARC Fails and How to Fix ItDMARC fails when neither SPF nor DKIM passes for a domain aligned with your From address. Usually a sender lacks custom DKIM. Here's how to find and fix it.
- DMARC Policy: p=none vs quarantine vs reject (and Getting to Enforcement)p=none only monitors, p=quarantine asks receivers to junk failing mail, p=reject asks them to refuse it. Start at none, fix your senders, then tighten.
- DMARC Record Syntax and Tags ExplainedA DMARC record is a TXT record at _dmarc.yourdomain with tags for policy, reporting and alignment. Here's what each tag does and what's changed under DMARCbis.
Still stuck?
Some deliverability problems take an experienced eye to untangle. Tell me what you're seeing and I'll tell you what I'd check first. The first 30-minute call is free.