Set up DMARC, SPF and DKIM in Microsoft 365

Written by Micronet AS · Updated

Short answer

How do I set up DMARC, SPF and DKIM in Microsoft 365?

For a domain that only sends from Microsoft 365, you add three things in DNS: the SPF record v=spf1 include:spf.protection.outlook.com -all, two CNAME records for DKIM (selector1 and selector2) with the values you find in the Defender portal, and a DMARC record at _dmarc, first with p=none. Then you turn on DKIM signing in the portal.

Microsoft 365 does not sign email with your own domain until you have turned it on. Without it, email often passes DMARC only through SPF, which does not survive forwarding. This guide follows the documentation from Microsoft.

Before you start

You need access to DNS for the domain and an administrator role in Microsoft 365. Make a list of every service that sends email with your domain in the From address: newsletters, invoicing, website, scanners. They must be part of the setup too.

Step 1: SPF

TXT record at company.comv=spf1 include:spf.protection.outlook.com -all

Microsoft recommends -all for domains in Microsoft 365, because they also recommend DKIM and DMARC. The domain can only have one SPF record. If other services send for the domain, you add them to the same record, before -all.

SPF allows at most 10 DNS lookups. If you have many services, see the guide to the SPF limit.

Step 2: DKIM

Microsoft uses two selectors, selector1 and selector2, and switches between them when the keys are renewed. You create two CNAME records that point to Microsoft. The values are different for every customer, so get them from the portal and not from an example.

  1. Open security.microsoft.com/authentication, or go to Email & collaboration, Policies & rules, Threat policies, Email authentication settings, and choose the DKIM tab.
  2. Select the domain. Under "Publish CNAMEs" you find the two records to create.
  3. Add selector1._domainkey and selector2._domainkey as CNAME at your DNS provider.
  4. Wait a few minutes, and turn on "Sign messages for this domain with DKIM signatures".
The domain was addedThe CNAME record points to
Before May 2025selector1-company-com._domainkey.company.onmicrosoft.com
From May 2025selector1-company-com._domainkey.company.n-v1.dkim.mail.microsoft

The letter before -v1 varies and cannot be chosen. You can also get the values with PowerShell: Get-DkimSigningConfig -Identity company.com | Format-List Selector1CNAME,Selector2CNAME.

Check the key length with the DKIM key strength tool. If the key is 1024 bits, you move to 2048 bits with Rotate-DkimSigningConfig -Identity company.com -KeySize 2048.

Step 3: DMARC

TXT record at _dmarc.company.comv=DMARC1; p=none; rua=mailto:dmarc@company.com

Start with p=none, read the reports, and tighten. The goal Microsoft sets is p=reject for all custom domains and subdomains. The method is in the guide to DMARC policy.

Do not forget the onmicrosoft.com domain

Every customer has a domain that ends in onmicrosoft.com. It can be abused too. Microsoft recommends a DMARC record with reject for it, and you add it in the Microsoft 365 admin center under Settings, Domains, select the onmicrosoft.com domain, DNS records, Add record.

TXT record named _dmarc on the onmicrosoft.com domainv=DMARC1; p=reject

Reports from Microsoft

Microsoft 365 sends aggregate reports to the address in rua for domains where the MX record points directly to Microsoft 365. Microsoft 365 does not send failure reports (ruf).

Check the setup

Use the SPF checker, the DKIM checker and the DMARC checker, or send an email to the email deliverability test, which shows whether SPF, DKIM and DMARC passed for a real email.

Sources

Questions and answers

Why does Microsoft 365 have two DKIM selectors?

To be able to change keys without interruption. Microsoft signs with one selector and renews the other, and then switches. Both CNAME records must therefore be in DNS all the time.

Should SPF end with -all or ~all?

Microsoft recommends -all for domains in Microsoft 365. Google recommends ~all for Google Workspace. When the domain has DKIM and DMARC with enforcement, the difference is small in practice.

What do I do with domains that do not send email?

Give them the SPF record v=spf1 -all and the DMARC record v=DMARC1; p=reject. Microsoft does not recommend DKIM records for parked domains.