Skip to content
TECHNOARTH IT for offices and small businesses.
Security

How to set up SPF, DKIM and DMARC (Microsoft 365, Workspace)

The three DNS records that keep your company's email out of spam and make it harder for scammers to send fake invoices from your domain. Setup by provider and how to check it worked.

How to set up SPF, DKIM and DMARC (Microsoft 365, Workspace)

When your invoices land in a customer’s junk folder, or a supplier receives a payment request that looks like it came from your accounts team, the cause is usually three DNS records: SPF, DKIM and DMARC. Together they tell receiving mail servers who is allowed to send for your domain and what to do with anyone pretending to be you.

These records are no longer optional. Since February 2024, the Gmail sender guidelines have required SPF or DKIM from everyone who sends to Gmail accounts, and senders above 5,000 messages a day also need DMARC.

In this article
  1. What each record does
  2. Before you change anything: list everything that sends as your domain
  3. Step 1: set up SPF (one record only)
  4. Step 2: turn on DKIM in each service
  5. Step 3: publish DMARC in monitoring mode first
  6. Step 4: check that it worked
  7. If something fails
  8. Which path to take
  9. Frequently asked questions

What each record does

RecordWhat it checksWhere it lives in DNS
SPFWhich servers may send mail for the domainTXT at the root (@)
DKIMWhether the message was signed by the domain and arrived unchangedTXT or CNAME at selector._domainkey
DMARCWhat to do when SPF and DKIM fail, and where to send reportsTXT at _dmarc

Before you change anything: list everything that sends as your domain

There are almost always more senders than you expect:

  • Your mailbox provider (Microsoft 365, Google Workspace or your web host’s email).
  • Invoicing, accounting or ERP software that emails documents.
  • Website contact forms, newsletter tools and the CRM.
  • The multifunction printer that scans to email using an address on your domain.

For each one, note the SPF snippet and the DKIM instructions from the service’s own documentation. Also take a screenshot of the TXT records that already exist in your DNS panel (Cloudflare, your registrar, Hostinger or wherever the zone is hosted).

Step 1: set up SPF (one record only)

SPF is a single TXT record at the root of the domain listing the authorized senders. Each service is added with an include:

ProviderSPF snippet
Microsoft 365include:spf.protection.outlook.com
Google Workspaceinclude:_spf.google.com
Hostinger emailinclude:_spf.mail.hostinger.com

Example with Microsoft 365 plus a billing service:

v=spf1 include:spf.protection.outlook.com include:billing-service.example.com -all
  1. In your DNS panel, edit the TXT record that starts with v=spf1 (or create one with the name @) and put every include in that one record.
  2. Pick the ending. Microsoft’s SPF documentation recommends -all once DKIM and DMARC are also in place; ~all is softer and useful while you’re still discovering senders.

Companies that switched providers often keep the old SPF record by accident. Check from PowerShell:

Command
Resolve-DnsName yourdomain.com -Type TXT | Select-Object -ExpandProperty Strings
PowerShell with Resolve-DnsName listing the domain's TXT records, with two v=spf1 records highlighted
Two v=spf1 records on the same domain — Microsoft 365's (1) and an old one from the hosting company (2) — make SPF return permerror. Merge what is still in use into a single record and delete the other.

If two lines begin with v=spf1, SPF as a whole returns permerror. It also fails when the total number of lookups goes over 10: every include, a, mx, exists and redirect counts, including the nested ones inside each include; ip4: and ip6: don’t count.

Step 2: turn on DKIM in each service

Microsoft 365. In the Microsoft Defender portal, go to Email & collaboration › Policies & rules › Threat policies › Email authentication settings and open the DKIM tab. Select your domain and use Create DKIM keys; the flyout then shows two CNAME records, selector1._domainkey and selector2._domainkey. On newer domains the target ends in dkim.mail.microsoft, on older ones in onmicrosoft.com, so copy exactly what the portal shows. Once the records are published, turn on Sign messages for this domain with DKIM signatures.

Google Workspace. In the Admin console, open Apps › Google Workspace › Gmail › Authenticate email, choose the domain and click Generate new record. Choose a 2048-bit key if your DNS host accepts it (otherwise 1024) and keep the google prefix. Publish the TXT record at google._domainkey, and only then click Start authentication. Google’s DKIM page notes that authentication can take up to 48 hours to start working.

Hostinger. DKIM comes as three CNAME records (hostingermail-a._domainkey, -b and -c); if your DNS is hosted somewhere else, copy them from hPanel.

Repeat for every item on your list. Invoicing tools, CRMs and newsletter platforms have their own DKIM, usually on a screen called something like “domain authentication”.

Step 3: publish DMARC in monitoring mode first

Create a TXT record named _dmarc:

v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com
  • p=none blocks nothing; it only asks for reports.
  • rua= receives the aggregate reports, typically one a day from each large mailbox provider.

Use a mailbox or group just for this. The reports arrive as compressed XML listing the IP addresses and volumes that sent as your domain, without message content. If you pay a service to read them, treat it like any supplier that receives company data: a contract and restricted access.

When every legitimate service passes in the reports, tighten the policy gradually, as Microsoft’s DMARC guidance describes:

  1. p=quarantine; pct=10, then 25, 50, 75 and 100: the share of failing messages sent to quarantine or the junk folder.
  2. p=reject: the receiving server refuses the forged message.

Domains you registered only to protect your brand, and that never send mail, can go straight to v=spf1 -all and v=DMARC1; p=reject.

Step 4: check that it worked

In PowerShell, query DMARC and DKIM (repeat with selector2; for Google, query google._domainkey with -Type TXT):

Command
Resolve-DnsName _dmarc.yourdomain.com -Type TXT | Select-Object -ExpandProperty Strings
Resolve-DnsName selector1._domainkey.yourdomain.com -Type CNAME | Select-Object -ExpandProperty NameHost
PowerShell showing the DMARC record in p=none mode and the Microsoft 365 DKIM selector1 CNAME resolving in DNS
DMARC (1) already resolves, in monitoring mode, and the DKIM CNAME (2) points to Microsoft. Repeat the second query with selector2.

Next, send a message to a Gmail account. Open it there, click More (the three dots next to Reply) and choose Show original. The summary at the top should list SPF, DKIM and DMARC as PASS.

To inspect a message you received in classic Outlook, double-click it to open it in its own window, go to File › Properties and read the Internet headers box. In the new Outlook, use More actions › View › View message details. Look for the Authentication-Results line; the values are explained on Microsoft’s anti-spam message headers page.

Classic Outlook Properties window with the Internet headers box showing spf=fail, dkim=none and dmarc=fail action=none for a message using the company's domain
Fake message using the company's domain: it failed SPF and DKIM, and DMARC failed too (1), but action=none shows the p=none policy did not ask for blocking.

In this example the forged message failed every check, yet DMARC requested no action (action=none) because the domain was still at p=none. Microsoft’s filter recorded the failure (compauth=fail), but another provider could deliver the same message normally, which is exactly why you shouldn’t stay at the first stage. If someone on your team already replied to a message like this, also follow the hacked email checklist and go over how to spot phishing with the team.

If something fails

Which path to take

Your situationWhere to start
Mailboxes only in Microsoft 365 or GoogleSPF with -all, DKIM in the provider’s admin panel and DMARC at p=none, all on the same day
Several systems sending as your domainSPF with ~all, DKIM in each service and a few weeks of reports before moving to quarantine
Still choosing an email platformRead the Google Workspace vs Microsoft 365 comparison; both set up DKIM from their admin panel

Frequently asked questions

Do I need all three records, or is SPF enough?

All three. SPF doesn’t protect the From address the recipient actually sees; only DMARC tells receivers what to do when someone uses your domain without permission.

Can I start straight at p=reject?

Not on a domain that’s in use. Without the p=none period, a forgotten invoicing or billing system gets its mail rejected, and nobody notices until a customer complains.

Everything is set up and my email still goes to spam. Now what?

Authentication is a prerequisite, not a guarantee. Domain reputation, old mailing lists and content also matter, and Gmail asks senders to keep their reported spam rate below 0.3%.

Share

About the author

TECHNOARTH Editorial Team

The TECHNOARTH newsroom: technology tutorials, guides, comparisons and news produced with AI assistance and checked against manufacturers’ official sources.

Reviewed by Arth Moraes — Arth Moraes is the editorial pen name of the person responsible for TECHNOARTH, who sets the agenda, reviews and approves every tutorial before publication and is accountable for corrections.