SPF, DMARC, and DKIM Setup Guide: Protect Your Domain from Email Spoofing

SPF, DMARC, and DKIM Setup Guide: Protect Your Domain from Email Spoofing

Email spoofing is one of the most common and effective attack vectors against businesses of all sizes. An attacker sends an email that appears to come from your domain but actually comes from their server, tricking employees, customers, or partners into clicking malicious links or transferring money. The attack works because email, by default, has no authentication—it's trivially easy to forge the "From" address. SPF, DMARC, and DKIM exist to solve this problem by authenticating email and preventing spoofing. Yet most organizations haven't implemented them, leaving their domains vulnerable. This guide walks you through the technical implementation of email authentication, from DNS record configuration to testing and troubleshooting, so you can close this critical security gap in your domain.

Email authentication DNS records configuration

Understanding Email Authentication and Why You Need It

Email authentication mechanisms answer three questions: Is this email actually from who it claims to be? Can we cryptographically prove who sent it? What should we do if the answer is no? SPF, DMARC, and DKIM provide these answers through DNS records that email providers query when they receive messages from your domain.

Without authentication, an attacker can send an email with "From: ceo@yourcompany.com" and it appears legitimate to recipients. The attacker doesn't need to access your email servers—they just need to send an email through any mail server and forge the From header. This is devastating for phishing attacks: a spoof email from your CEO asking employees to transfer funds or reset passwords is shockingly effective. Business email compromise (BEC) attacks exploit unauthenticated email to extract millions from companies annually. SPF, DMARC, and DKIM prevent this by making it mathematically difficult to forge emails from your domain.

SPF is foundational—it lists which servers are authorized to send email from your domain. DKIM adds cryptographic signatures to prove the email came from a server you authorized. DMARC ties them together and tells receiving mail servers how to handle authentication failures. Together, they make email spoofing technically difficult and give receiving mail servers confidence that emails from your domain are legitimate. Email providers (Gmail, Outlook, etc.) increasingly require these mechanisms for good deliverability. Some major mail providers now refuse to accept unauthenticated email from corporate domains.

Implementing SPF: Authorizing Your Mail Senders

SPF records are DNS TXT records that list IP addresses and domains authorized to send email from your domain. Start by identifying all services that send email on your behalf: your email provider (Gmail, Office 365, Zoho), transactional email services (SendGrid, Mailgun), marketing platforms (Mailchimp, HubSpot), notification services, payment processors, and any internal mail relays.

For each service, get the SPF include string from their documentation. Most major services publish SPF includes specifically for this purpose. For example: SendGrid's include is include:sendgrid.net, Mailchimp's is include:servers.mcsv.net. These includes tell mail receivers to check that service's SPF records for the actual authorized IPs. Building your SPF record is straightforward: combine all the includes plus your own mail server (if you have one) into a single SPF record.

The syntax is: v=spf1 [mechanisms] [qualifier]. Mechanisms are either includes (include:service.com) or direct IP addresses (ip4:203.0.113.0 or ip6:2001:db8::1). The qualifier at the end controls the handling of non-matching senders: ~all (soft fail—accept but mark suspect), -all (hard fail—reject), +all (accept all, defeats the purpose), or ? (neutral). Use ~all initially while testing, then move to -all once you're certain your SPF record is complete.

A typical SPF record for a small company might look like: v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.5 ~all. Log into your domain registrar or DNS provider, create a new TXT record for your domain (not a subdomain), and paste your SPF record. DNS changes can take 24 hours to propagate, but most updates propagate within minutes.

After publishing your SPF record, check it for errors using MXToolbox's SPF checker. It will highlight syntax errors, overly long records (SPF has a 255 character limit, sometimes requiring optimization), and configuration issues. The most common problem is including too many services—SPF records have a 10 include limit. If you exceed it, consolidate or remove less critical services.

Configuring DKIM: Cryptographic Proof of Origin

DKIM requires generating a keypair: a private key that your mail server uses to sign outgoing emails, and a public key that receivers use to verify the signature. Most email services handle this automatically—you don't generate the keypair yourself. Instead, your email provider generates it and gives you the public key to add to DNS.

Log into your email provider's settings and locate the DKIM configuration section. For Google Workspace, this is under Security > Authentication. For Microsoft 365, it's under Exchange admin center > Mail flow > DKIM. For SendGrid, it's under Settings > Sender Authentication > DKIM. Each provider gives you a DNS record or set of records to add. The record looks like: default._domainkey IN CNAME sendgrid.net. or a long TXT record containing the public key itself.

Add the DKIM DNS record to your domain. If your provider gives you multiple records (one for each mail server or region), add all of them. Test the record using MXToolbox's DKIM checker—it verifies that your public key is correctly published and queryable. Some providers require you to confirm the DKIM setup in their admin console after publishing the DNS record.

For multiple email providers (e.g., Google Workspace for employee email plus SendGrid for transactional email), you'll have multiple DKIM selectors. This is fine—each provider's system will use its own DKIM key to sign emails, and mail receivers will verify each signature. Gmail messages will be signed with Gmail's key, SendGrid messages with SendGrid's key.

Enforcing Authentication with DMARC

DMARC policies tell receiving mail servers what to do when emails from your domain fail SPF or DKIM checks. Start with a monitoring policy to identify any legitimate services that might fail: v=DMARC1; p=none; rua=mailto:dmarc-reports@yourdomain.com. This tells mail servers to accept all mail but send you daily aggregate reports showing what passed and failed SPF/DKIM.

Review these reports for two weeks. You'll see patterns: legitimate services that configured SPF correctly, any services that didn't, and phishing attempts (which will typically fail both SPF and DKIM). Once you're confident you've found all legitimate senders, upgrade to a stricter policy: v=DMARC1; p=quarantine; rua=mailto:dmarc-reports@yourdomain.com. Quarantine moves suspicious emails to spam instead of rejecting them—safer than rejection in case legitimate mail fails. After another week of monitoring, upgrade to: v=DMARC1; p=reject; rua=mailto:dmarc-reports@yourdomain.com. Reject tells mail servers to refuse email that fails SPF or DKIM, preventing spoofing entirely.

Add the DMARC record as a TXT record on _dmarc.yourdomain.com (not your root domain). You can also set p=quarantine or p=reject on subdomains (_dmarc.newsletter.yourdomain.com) separately from your main domain if you have different mail sources for different subdomains.

Testing and Ongoing Monitoring

After implementing all three mechanisms, test your configuration using multiple tools. MXToolbox's email authentication tester sends a test email and shows you exactly how major mail providers will handle it. 250ok and DKIM tester provide similar functionality. Send test emails from your domain and check them against these tools.

Monitor DMARC reports for unusual patterns. A sudden spike in failing emails might indicate an active spoofing attack—now that you have DMARC in place, those forged emails are being blocked automatically. Watch for any legitimate services that are failing authentication and update your SPF or DKIM configuration to include them.

Email authentication requires maintenance. When you add a new email service or integrate a new platform that sends email on your behalf, immediately update your SPF record to include it. When a mail provider changes their infrastructure or certificate (which happens annually), they'll notify you and provide updated DKIM records—update them promptly. Failing to maintain these records results in degraded deliverability and leaves you vulnerable to spoofing for any services that aren't configured.

Email spoofing is trivial to prevent with proper authentication setup. SPF, DMARC, and DKIM take a few hours to implement, cost nothing, and prevent an entire attack vector that currently works against most organizations. Once configured, they work continuously without ongoing effort, blocking spoofed emails and protecting your domain reputation.

RedRadar can audit your email authentication setup to ensure SPF, DMARC, and DKIM are properly configured, test your implementation against real mail provider standards, and identify any legitimate services that might be failing authentication.

Someone is sending emails that look like they're from your company right now. They use your domain, your company name, and a convincing subject line — and your email server can't stop it. This is email spoofing, and it's one of the most common ways attackers target your customers and partners. The fix is three DNS records: SPF, DKIM, and DMARC. Here's how to set them up correctly.

What Are SPF, DKIM, and DMARC?

These three protocols work together to prove that an email claiming to come from your domain was actually sent by you.

SPF (Sender Policy Framework)

SPF is a DNS record that lists which mail servers are allowed to send email for your domain. When someone receives an email from @yourcompany.com, their mail server checks your SPF record to see if the sending server is on the approved list. If it's not, the email fails SPF.

DKIM (DomainKeys Identified Mail)

DKIM adds a cryptographic signature to every outgoing email. The receiving server checks this signature against a public key published in your DNS. If the signature is valid, it proves the email wasn't tampered with in transit and actually originated from an authorized sender.

DMARC (Domain-based Message Authentication, Reporting and Conformance)

DMARC is the policy layer on top of SPF and DKIM. It tells receiving mail servers what to do when an email fails authentication: none (just monitor), quarantine (send to spam), or reject (block entirely). It also sends you reports showing who's sending email on behalf of your domain.

Why This Matters for Startups

Without these three records, anyone can send email that appears to come from your domain. Attackers use this to:

  • Impersonate your company to customers, asking for payments or credentials
  • Spoof invoices to your accounting team (BEC — Business Email Compromise)
  • Send phishing emails that bypass basic spam filters because they look legitimate
  • Damage your domain's email reputation, causing your real emails to land in spam

Enterprise clients increasingly check for DMARC before signing contracts. Missing it can cost you deals.

How to Set Up SPF

Log into your DNS provider and create a TXT record for your root domain (@ or yourdomain.com).

Basic SPF record if you send email through Google Workspace:

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

If you also use a platform like SendGrid or Mailchimp:

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

The ~all means "soft fail" (log but don't block). Once you're confident, switch to -all (hard fail — reject unauthorized senders). Start with ~all to avoid breaking legitimate email flows.

Important: You can only have one SPF record per domain. If you have multiple, combine them into one.

How to Set Up DKIM

DKIM is configured in your email provider's settings, not just in DNS. The provider generates a key pair for you.

  • Google Workspace: Admin Console → Apps → Google Workspace → Gmail → Authenticate email → Generate new record
  • Microsoft 365: Exchange Admin Center → Protection → DKIM → Enable for your domain
  • SendGrid: Settings → Sender Authentication → Domain Authentication

Your email provider will give you a TXT record to add to your DNS. It looks like this:

google._domainkey.yourdomain.com  TXT  "v=DKIM1; k=rsa; p=MIGfMA0GCS..."

Add it and wait for DNS propagation (up to 48 hours, usually much faster).

How to Set Up DMARC

Add a TXT record at _dmarc.yourdomain.com. Start in monitoring mode:

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

This tells mail servers to take no action on failures but send you daily aggregate reports. After reviewing the reports for a few weeks (you'll see which services send on your behalf), tighten the policy:

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

pct=50 applies the quarantine policy to 50% of failing mail — a safe ramp-up. When you're confident, go to full enforcement:

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

How to Verify Your Setup

Use these free tools to confirm everything is configured correctly:

Practical Takeaways

  • Set up SPF first — it's the quickest win and requires only one DNS record
  • Enable DKIM through your email provider — each provider has its own setup flow
  • Start DMARC at p=none to monitor without breaking email, then tighten over weeks
  • Don't forget subdomains — attackers can spoof billing.yourcompany.com too. Add DMARC with sp=reject to cover them
  • Audit all services that send email on your behalf (CRMs, marketing tools, support platforms) and add them to your SPF record before enforcing DMARC
  • Check SPF isn't over 10 DNS lookups — that breaks it silently. Use a flattening tool if needed

SPF, DKIM, and DMARC protect your email channel — but they're one layer of your overall security posture. Want to know what else attackers can see about your domain, subdomains, and infrastructure? RedRadar runs a full external security scan and delivers a professional report in 24 hours. Order your security report here →

🔍 FREE SECURITY SCAN

Know what attackers see about your company

Get a full external security report — subdomains, open ports, leaked credentials, DNS health, and more. Delivered in 24 hours.

Order Your Security Report →