SPF, DKIM and DMARC are three DNS-based checks that prove your email really comes from you. Together they stop spoofing and keep your messages out of spam. Setting them up for Microsoft 365 takes about thirty minutes of work, then a few weeks of watching reports. This guide uses contoso.com as the example; replace it with your own domain.
Before you begin
You need admin access to your DNS provider (where your domain's records live) and a Global Administrator or Security Administrator account in Microsoft 365. Write down every service that sends email as your domain, such as newsletters or invoicing tools, because each one needs to be covered.
What each record does
- SPF lists the servers that are allowed to send mail for your domain.
- DKIM adds a signature to each message so receivers can confirm it was not altered and came from your domain.
- DMARC tells receivers what to do when SPF and DKIM fail, and sends you reports about who is using your domain.
Step 1: Create or fix the SPF record
Add one TXT record at the root of your domain (host name @):
v=spf1 include:spf.protection.outlook.com -all
- A domain may have only one SPF record. If one exists, edit it rather than adding a second.
- Add other senders inside the same record, for example
include:servers.mcsv.netfor a newsletter tool. - SPF allows at most 10 DNS lookups. Too many include statements break it.
- Use ~all while testing, then -all when you are sure.
Step 2: Publish the DKIM CNAME records
Microsoft 365 signs mail with two keys, called selectors. Add two CNAME records at your DNS host:
selector1._domainkey.contoso.com pointing to selector1-contoso-com._domainkey.contoso.onmicrosoft.com
selector2._domainkey.contoso.com pointing to selector2-contoso-com._domainkey.contoso.onmicrosoft.com
The part before .onmicrosoft.com is your tenant's initial domain, so check the exact values shown in the Defender portal. Some DNS providers add your domain automatically, so enter only the host part if your records end up doubled.
Step 3: Enable DKIM signing
- Sign in to the Microsoft Defender portal and open Email and collaboration, then Policies and rules, then Threat policies, then Email authentication settings.
- Choose the DKIM tab and select your domain.
- Switch on "Sign messages for this domain with DKIM signatures".
- If it errors, wait for DNS to propagate and try again.
Step 4: Add a DMARC record
Create a TXT record with the host name _dmarc:
v=DMARC1; p=none; rua=mailto:dmarc-reports@contoso.com
p=none means "monitor only". Reports will arrive as XML attachments, and a free DMARC report reader makes them easy to read. The mailbox in rua must exist.
Step 5: Move DMARC to enforcement
After two to four weeks, confirm every legitimate sender passes SPF or DKIM aligned with your domain. Then tighten the policy in stages: p=quarantine first, and p=reject once reports stay clean. Moving too fast is the most common way to block your own invoices or newsletters.
Step 6: Test everything
From a command prompt, check each record:
nslookup -type=txt contoso.comshows your SPF record.nslookup -type=cname selector1._domainkey.contoso.comshows the DKIM pointer.nslookup -type=txt _dmarc.contoso.comshows DMARC.
Then email a Gmail address, open the message, choose "Show original" and confirm SPF, DKIM and DMARC all say PASS.
Protect domains that never send mail
Attackers also spoof domains you own but do not use, such as old brand names or parked domains. For each of them, publish an SPF record of v=spf1 -all and a DMARC record of v=DMARC1; p=reject;. If your main domain uses subdomains for sending, the sp= tag in DMARC controls the policy for those subdomains separately.
Reading your DMARC reports
The aggregate reports list every source that sent mail using your domain, with SPF and DKIM results for each. Look for sources you recognise that fail, and fix those first. Sources you do not recognise are either forgotten services or someone spoofing you. A free report viewer turns the XML into a readable table.
Common problems
Duplicate SPF records, forgotten third-party senders, missing DKIM CNAMEs and DMARC set to reject too early cause nearly every failure. If mail still lands in junk after everything passes, read our guide on Office 365 emails going to spam.
Frequently asked questions
Do I need all three of SPF, DKIM and DMARC?
Yes. SPF and DKIM prove a message is legitimate, and DMARC tells receivers what to do when they fail and sends you reports.
Where do I find my onmicrosoft.com domain?
In the Microsoft 365 admin center under Settings, Domains. The initial domain ends in onmicrosoft.com, and the Defender DKIM page shows the exact CNAME values.
What does p=none do in DMARC?
It only monitors. Failing mail is still delivered, but you receive reports so you can fix problems before enforcing.
How do I know DKIM is working?
Send a message to Gmail and use Show original. A line reading DKIM: PASS with your domain confirms signing works.
Need help? Chat on WhatsApp