The Complete SPF, DKIM & DMARC Setup Guide
Table of Contents
- 1. Why Email Authentication Matters
- 2. Understanding SPF (Sender Policy Framework)
- 3. Setting Up SPF Records
- 4. Understanding DKIM (DomainKeys Identified Mail)
- 5. Setting Up DKIM
- 6. Understanding DMARC (Domain-based Message Authentication)
- 7. Setting Up DMARC
- 8. Testing Your Configuration
- 9. Common Mistakes to Avoid
- 10. Monitoring and Maintenance
Why Email Authentication Matters
Email authentication is the foundation of email security. Without it, anyone can send emails that appear to come from your domain. This leads to phishing attacks against your customers, damaged brand reputation, and poor email deliverability for your legitimate messages.
According to industry data, over 3.4 billion phishing emails are sent daily. Email authentication protocols like SPF, DKIM, and DMARC work together to verify that messages genuinely originate from your domain and have not been tampered with in transit.
Major email providers like Google and Microsoft now require proper authentication for bulk senders. Starting in 2024, Gmail requires SPF or DKIM for all senders, and DMARC for those sending more than 5,000 messages per day. Without these records, your emails will increasingly land in spam or be rejected entirely.
Understanding SPF (Sender Policy Framework)
SPF is a DNS-based authentication protocol that specifies which mail servers are authorized to send email on behalf of your domain. When a receiving server gets an email claiming to be from your domain, it checks your SPF record to verify the sending server is on the approved list.
SPF works by publishing a TXT record in your domain's DNS. This record contains a list of IP addresses and hostnames that are permitted to send mail for your domain. The receiving server performs a DNS lookup, compares the sending server's IP against your SPF record, and returns a pass or fail result.
Key limitations of SPF include: it only checks the envelope sender (not the header "From" address visible to users), it breaks when emails are forwarded, and you are limited to 10 DNS lookups per SPF evaluation. This is why SPF alone is insufficient and must be combined with DKIM and DMARC.
Setting Up SPF Records
To set up SPF, you need to identify all services that send email on behalf of your domain. This includes your primary mail server, any marketing platforms (Mailchimp, SendGrid), CRM systems, and transactional email services.
Here is an example SPF record for a business using Google Workspace and Mailchimp:
v=spf1 include:_spf.google.com include:servers.mcsv.net ~all
Breaking this down:
v=spf1declares this is an SPF version 1 recordinclude:_spf.google.comauthorizes Google Workspace serversinclude:servers.mcsv.netauthorizes Mailchimp servers~allsoft-fails for any server not listed (recommended during initial setup)
Once you have confirmed everything works correctly, change ~all to -all for a hard fail, which provides stronger protection against unauthorized senders.
Understanding DKIM (DomainKeys Identified Mail)
DKIM adds a cryptographic signature to outgoing emails. The sending server signs each message with a private key, and the corresponding public key is published in your DNS. Receiving servers use the public key to verify the signature, confirming the message was not altered in transit.
Unlike SPF, DKIM survives email forwarding because the signature is attached to the message itself, not tied to the sending server's IP address. This makes DKIM particularly important for messages that may pass through mailing lists or be forwarded by recipients.
DKIM uses a selector to allow multiple keys for the same domain. This is useful when different services (your main mail server, a marketing platform, a ticketing system) each need their own signing key. Each service publishes its public key under a unique selector.
Setting Up DKIM
DKIM setup varies by email provider. Your provider generates the key pair and gives you a DNS record to publish. Here is an example DKIM record for Google Workspace:
Host: google._domainkey.yourdomain.com
Type: TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
Steps to enable DKIM with Google Workspace:
- Go to Google Admin Console, then Apps, Google Workspace, Gmail, Authenticate Email
- Select your domain and click "Generate new record"
- Choose your DKIM key bit length (2048-bit recommended)
- Copy the generated DNS record
- Add the TXT record to your domain's DNS zone
- Wait for DNS propagation (up to 48 hours, usually faster)
- Return to Admin Console and click "Start authentication"
For other providers like Microsoft 365, the process is similar but uses different selectors (selector1 and selector2) and CNAME records instead of TXT records. Always follow your specific provider's documentation for the exact setup steps.
Understanding DMARC (Domain-based Message Authentication)
DMARC ties SPF and DKIM together and tells receiving servers what to do when authentication fails. It also provides a reporting mechanism so you can monitor who is sending email using your domain. DMARC checks that the domain in the visible "From" header aligns with the domains authenticated by SPF or DKIM.
DMARC introduces the concept of "alignment." For SPF alignment, the envelope sender domain must match the header From domain. For DKIM alignment, the signing domain (d= tag) must match the header From domain. DMARC passes if either SPF or DKIM passes with proper alignment.
DMARC policies have three enforcement levels: none (monitor only), quarantine (send to spam), and reject (block entirely). You should start with "none" to collect data, then gradually increase enforcement as you confirm all legitimate sources are properly authenticated.
Setting Up DMARC
DMARC is published as a TXT record at _dmarc.yourdomain.com. Here is a recommended starting configuration:
v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com; ruf=mailto:dmarc-forensics@yourdomain.com; fo=1;
Breaking down the tags:
v=DMARC1- Protocol version identifierp=none- Policy: none, quarantine, or rejectrua=mailto:- Aggregate report destination (daily summaries)ruf=mailto:- Forensic report destination (individual failures)fo=1- Generate forensic report if any mechanism fails
Recommended progression path for DMARC enforcement:
Week 1-4: p=none (monitor and review reports)
Week 5-8: p=quarantine; pct=25 (quarantine 25% of failures)
Week 9-12: p=quarantine; pct=100 (quarantine all failures)
Week 13+: p=reject (block all unauthenticated mail)
Testing Your Configuration
After publishing your records, verify they work correctly. Use command-line DNS tools to confirm records are published:
dig TXT yourdomain.com # Check SPF record
dig TXT google._domainkey.yourdomain.com # Check DKIM
dig TXT _dmarc.yourdomain.com # Check DMARC
Send Test Emails: Send messages to Gmail, Outlook, and Yahoo accounts. Check the email headers for authentication results. In Gmail, click "Show Original" to see SPF, DKIM, and DMARC pass/fail status for the message.
Online Validation Tools: Use services like MXToolbox, Mail Tester, or Google Admin Toolbox to check your DNS records for syntax errors. These tools identify missing records and potential configuration problems before they cause deliverability issues.
DMARC Report Analysis: After 24-48 hours, aggregate reports will arrive. Use a DMARC report analyzer to parse the XML data and identify unauthorized senders or authentication failures requiring your attention.
Common Mistakes to Avoid
These common mistakes can undermine your email authentication:
- Multiple SPF records: Only one SPF TXT record per domain is allowed. Multiple records cause all SPF checks to fail. Combine all includes into a single record.
- Exceeding the 10-lookup limit: Each "include" and "redirect" counts as a DNS lookup. Nested includes count too. Use IP addresses directly or flatten your SPF record if you approach the limit.
- Forgetting third-party senders: Audit all services sending email as your domain: invoicing software, CRM, helpdesk, monitoring alerts, marketing tools. Missing one causes authentication failures for those messages.
- Jumping straight to p=reject: Never skip monitoring. Going directly to reject will block legitimate mail and cause business disruption. Follow the gradual enforcement path described above.
- Ignoring DMARC reports: Publishing a DMARC record with p=none and never reading reports defeats the purpose. Review reports weekly and resolve any failures you find.
- Wrong SPF mechanism: Using "+all" (pass everything) or omitting the "all" mechanism entirely leaves your domain unprotected. Always end with "-all" or "~all".
Monitoring and Maintenance
Email authentication is not a set-and-forget configuration. Ongoing maintenance is essential for continued protection:
Review DMARC reports regularly. Set a weekly schedule to check aggregate reports. Look for unknown senders using your domain, authentication failures from legitimate services, and volume changes that might indicate abuse.
Update records when services change. Adding or removing email services requires immediate SPF record updates. Changing email providers means updating DKIM records and generating new signing keys.
Rotate DKIM keys periodically. Best practice is to rotate keys every 6-12 months. This limits exposure if a key is compromised. Most providers make key rotation straightforward through their admin interfaces.
Monitor deliverability metrics. Track bounce rates, spam complaints, and inbox placement. A sudden drop in deliverability may indicate an authentication problem requiring immediate attention.
Need Help With Email Authentication?
Our email deliverability service includes complete SPF, DKIM, and DMARC configuration, ongoing monitoring, and blacklist removal. Stop landing in spam.
View Email Deliverability Service