SPF, DKIM, DMARC Setup

How to Set Up SPF, DKIM, and DMARC: Complete Email Authentication Guide

30 min read • Email Authentication

Why Email Authentication Matters

Email authentication is the technical foundation of email deliverability. These protocols prove to receiving servers that your emails are legitimately from you and have not been tampered with or forged by malicious actors.

Without proper authentication, even legitimate emails face immediate suspicion. Email providers cannot distinguish you from spammers or phishers who might be pretending to be your domain. The result is increased spam filtering, lower inbox placement, and vulnerability to email spoofing attacks.

The Three Authentication Protocols

The Business Case for Authentication

Understanding SPF

SPF (Sender Policy Framework) is a DNS record that lists all servers and IP addresses authorized to send email on behalf of your domain. When someone receives an email claiming to be from @yourdomain.com, their server looks up your SPF record to verify the sending server is on your approved list.

How SPF Verification Works

  1. You send an email from sales@yourdomain.com
  2. The receiving server notes the sending IP address
  3. It queries DNS for yourdomain.com's SPF record
  4. Compares the sending IP against your authorized list
  5. If found, SPF passes. If not found, SPF fails.

SPF Record Syntax

An SPF record is a TXT record in DNS with specific syntax:

v=spf1 include:_spf.google.com include:sendgrid.net ip4:192.0.2.1 ~all

Breaking down the components:

Setting Up SPF Records

Step 1: Identify All Sending Sources

Before creating your SPF record, list every service that sends email using your domain:

Step 2: Build Your SPF Record

For Google Workspace:

v=spf1 include:_spf.google.com ~all

For Microsoft 365:

v=spf1 include:spf.protection.outlook.com ~all

For multiple services (example):

v=spf1 include:_spf.google.com include:sendgrid.net include:mailchimp.com ~all

Step 3: Add the Record to DNS

  1. Log into your domain registrar or DNS host (GoDaddy, Cloudflare, Namecheap, etc.)
  2. Navigate to DNS settings for your domain
  3. Add a new TXT record
  4. Set the host/name to @ (or your domain name)
  5. Paste your SPF record as the value
  6. Save and wait for propagation (usually minutes, up to 48 hours)

SPF Limitations and Rules

Understanding DKIM

DKIM (DomainKeys Identified Mail) uses public-key cryptography to prove emails were sent by you and have not been modified in transit. Each email is signed with a private key, and receivers verify the signature using your public key in DNS.

How DKIM Works

  1. You generate a public/private key pair
  2. The private key stays secure on your mail server
  3. The public key is published as a DNS TXT record
  4. When sending, your server creates a hash of email headers and body, then signs it with the private key
  5. The signature is added to email headers
  6. Receiving servers retrieve your public key from DNS and verify the signature

DKIM Provides

Setting Up DKIM

DKIM setup varies by email provider because each provider generates and manages the keys differently.

DKIM for Google Workspace

  1. Go to Google Admin Console (admin.google.com)
  2. Navigate to Apps > Google Workspace > Gmail
  3. Click Authenticate email
  4. Select your domain
  5. Click Generate new record
  6. Choose key length (2048-bit recommended)
  7. Copy the generated DKIM record
  8. Add as TXT record in your DNS at google._domainkey.yourdomain.com
  9. Return to Google Admin and click Start authentication

DKIM for Microsoft 365

  1. Go to Microsoft 365 Defender portal
  2. Navigate to Email & collaboration > Policies & rules > Threat policies > Email authentication settings
  3. Select DKIM tab
  4. Select your domain
  5. Toggle Enable to create DKIM signatures
  6. Copy the CNAME records provided
  7. Add both CNAME records to your DNS
  8. Return to Microsoft and verify

DKIM for Other Services

Most email services provide DKIM setup instructions. Common pattern:

  1. Find DKIM settings in the service's admin panel
  2. Generate or retrieve the DKIM public key
  3. Add as TXT or CNAME record at the specified selector._domainkey.yourdomain.com
  4. Verify in the service's settings

Multiple DKIM Keys

Each email service needs its own DKIM key. The selector mechanism allows multiple keys per domain:

Understanding DMARC

DMARC builds on SPF and DKIM by adding a policy layer and reporting mechanism. It tells receiving servers what to do when authentication fails and sends you reports about authentication results.

What DMARC Does

DMARC Alignment

DMARC adds an important concept: alignment. It is not enough for SPF or DKIM to pass; the authenticated domain must also match (align with) the visible From address domain.

DMARC Policies

Setting Up DMARC

Step 1: Start with Monitoring Policy

Always begin with p=none to monitor before enforcing:

v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com

Step 2: Add DMARC Record to DNS

  1. Log into your DNS management
  2. Add a TXT record
  3. Set host/name to _dmarc (resulting in _dmarc.yourdomain.com)
  4. Add your DMARC policy as the value
  5. Save and wait for propagation

Step 3: Monitor DMARC Reports

DMARC aggregate reports arrive as XML files to the email specified in rua=. Use a DMARC report analyzer to make sense of the data:

Review reports for 2-4 weeks to identify:

Step 4: Progress to Enforcement

After confirming legitimate email is passing authentication:

Move to quarantine (recommended intermediate step):

v=DMARC1; p=quarantine; pct=25; rua=mailto:dmarc-reports@yourdomain.com

The pct=25 applies the policy to only 25% of failing mail initially. Increase gradually.

Move to full reject (maximum protection):

v=DMARC1; p=reject; rua=mailto:dmarc-reports@yourdomain.com; ruf=mailto:dmarc-forensic@yourdomain.com

Testing Your Authentication

After setting up SPF, DKIM, and DMARC, verify everything is working correctly.

Quick Test with Mail-Tester

  1. Go to mail-tester.com
  2. Note the unique email address provided
  3. Send a test email to that address
  4. Return to the site for a detailed authentication report

Check Individual Records

SPF Check:

DKIM Check:

DMARC Check:

Send Test Emails

Send test emails to addresses at Gmail, Outlook, and Yahoo. Check the email headers to verify:

In Gmail, click the three dots > Show original to view full headers including authentication results.

Troubleshooting Common Issues

SPF Failures

Too many DNS lookups: SPF has a 10-lookup limit. Each include: counts as one. Solution: Use SPF flattening tools or ip4: mechanisms where possible.

Missing sending source: Emails from services not in your SPF record will fail. Audit all email sources and add them.

Multiple SPF records: Only one SPF record allowed per domain. Combine all authorizations into a single record.

DKIM Failures

Selector not found: The DNS record is not at the correct location. Verify selector._domainkey.yourdomain.com is correct.

Signature verification failed: Can indicate email modification in transit or key mismatch. Re-generate keys if persistent.

DNS propagation: New DKIM records may take up to 48 hours to propagate. Wait and retest.

DMARC Failures

Alignment failures: SPF or DKIM passes but domains do not align with From address. Common with third-party senders. Solution: Ensure services sign with your domain via DKIM.

Not receiving reports: Reports go to the email in rua=. Check spam folders. Ensure email address is valid and monitored.

Advanced Configuration

Subdomain Policies

DMARC allows separate policies for subdomains using sp= tag:

v=DMARC1; p=reject; sp=quarantine; rua=mailto:reports@yourdomain.com

Percentage Rollout

Use pct= to apply policy to only a percentage of failing mail:

v=DMARC1; p=quarantine; pct=50; rua=mailto:reports@yourdomain.com

BIMI (Brand Indicators for Message Identification)

BIMI allows displaying your logo in email clients. Requires DMARC with p=quarantine or p=reject. Add a DNS record:

default._bimi.yourdomain.com TXT "v=BIMI1; l=https://yourdomain.com/logo.svg"

Ongoing Maintenance

Regular Review Tasks

Documentation

Maintain documentation of:

WarmySender and Authentication

WarmySender requires proper email authentication for optimal deliverability. During mailbox connection, the system checks for SPF, DKIM, and DMARC configuration and provides guidance if improvements are needed. Proper authentication combined with WarmySender's warmup ensures the best possible inbox placement rates. All included in the $49 one-time lifetime plan.

Frequently Asked Questions

Do I need all three (SPF, DKIM, DMARC)?

Yes, all three work together for complete email authentication. SPF verifies the sending server is authorized. DKIM cryptographically proves the email is genuinely from you and unmodified. DMARC ties them together with policy enforcement and reporting. Gmail and Yahoo now require all three for bulk senders. Missing any one significantly weakens your authentication and deliverability.

What order should I set up SPF, DKIM, and DMARC?

Set up in this order: SPF first (usually simplest, one DNS record), then DKIM (requires key generation for each email service), then DMARC (last, as it depends on SPF and DKIM). Start DMARC with p=none policy for monitoring, review reports for 2-4 weeks, then progress to enforcement.

What happens if SPF fails?

SPF failure alone usually does not cause immediate rejection. The result depends on your DMARC policy: with p=none nothing happens, with p=quarantine the email may go to spam, with p=reject it may be blocked. SPF failures contribute to reputation damage over time. Common causes include missing include: statements for email services or exceeding the 10-lookup limit.

How do I fix SPF too many DNS lookups?

The SPF 10-lookup limit is a common issue. Solutions: 1) Replace include: with ip4: where IPs are static, 2) Use an SPF flattening service that converts includes to IP addresses, 3) Remove unused services from your SPF, 4) Consider a subdomain for some email categories with its own simpler SPF.

Why is DKIM failing even though I added the DNS record?

Common causes: 1) DNS propagation delay (wait 24-48 hours), 2) Wrong selector in the DNS record name, 3) Typo in the key value, 4) The email service is not enabled to sign with DKIM, 5) You are testing from a service not covered by that DKIM key. Use DKIM lookup tools to verify the record exists and is valid.

Should I start DMARC with p=reject?

No, always start with p=none for monitoring. DMARC reject policy blocks failing emails, including potentially legitimate mail from misconfigured sources you may not know about. Monitor with p=none for 2-4 weeks, fix any issues revealed in reports, then progress to p=quarantine with pct=25, gradually increasing to p=reject.

How do I read DMARC aggregate reports?

DMARC aggregate reports are XML files sent daily to the email in your rua= tag. They show authentication results for all emails claiming to be from your domain. Use DMARC analyzer tools like dmarcian, DMARC Analyzer, or Postmark DMARC to parse and visualize the data. Look for legitimate sources failing authentication (fix them) and unauthorized sources (your policy should block them).

Do I need to update authentication when adding new email services?

Yes. Before enabling email sending from any new service: 1) Add their sending servers to your SPF record with the appropriate include: statement, 2) Configure DKIM in the service and add the DKIM DNS record, 3) Test authentication before sending to real recipients. Failing to update authentication causes delivery failures from the new service.

Put This Knowledge Into Action

Start warming up your inbox today and see better deliverability results.

Get Started Free