Intermediate·15 min read·Updated 2026-10-15

DNS Security: SPF, DKIM & DMARC Implementation & Audit Guide

Original WeSecureX guide for authorized testing of sites you own. Linked Sources are citations for verification - not copied articles. Ads are not served on this page.

The Simple Mail Transfer Protocol (SMTP) - first designed in 1982 - contains zero native mechanisms to verify the authenticity of the sender's email address. In an unconfigured domain, any threat actor can connect to an open mail relay and dispatch forged emails displaying `From: ceo@yourcompany.com` directly to employees, customers, and business partners. To close this fundamental vulnerability, the internet engineering community introduced three interlocking DNS-based authentication protocols: **Sender Policy Framework (SPF)**, **DomainKeys Identified Mail (DKIM)**, and **Domain-based Message Authentication, Reporting, and Conformance (DMARC)**. In 2024-2026, major email providers including Google, Yahoo, and Microsoft began strictly rejecting incoming messages from domains lacking valid SPF and DMARC records. This guide details record syntax, cryptographic key deployment, and automated validation using the [WeSecureX DNS Record Lookup Tool](/tools/dns-record-lookup) and [Website Security Scanner](/scanner).

Quick Answer

Secure email and prevent domain spoofing by publishing an SPF TXT record listing authorized sending IPs, generating 2048-bit RSA DKIM keys for all email senders (Google Workspace, Microsoft 365, SendGrid), and enforcing a strict DMARC policy (`v=DMARC1; p=reject; rua=mailto:dmarc-reports@example.com`).

Key Takeaways
  • SPF validates sending server IP addresses; DKIM cryptographically signs message headers; DMARC enforces alignment.
  • Major email providers (Google, Yahoo, Microsoft) require SPF and DMARC for inbox delivery.
  • A DMARC policy of `p=none` is only for monitoring; real protection requires `p=quarantine` or `p=reject`.
  • Exceeding the 10-lookup limit in an SPF record causes critical delivery failures worldwide.
Visual Diagram · Email Authentication Pipeline: SPF, DKIM & DMARC Verification
1

1. Inbound Email

Sending server transmits an email claiming to originate from `billing@yourcompany.com`.

2

2. SPF IP Validation

Receiving server checks DNS TXT record to verify if the sending MTA's IP is authorized.

3

3. DKIM Cryptography

Receiver verifies the cryptographic digital signature in email headers using the public key in DNS.

4

4. DMARC Policy Action

Receiver checks DMARC alignment. If checks fail, policy (`p=reject`) discards the spoofed email.

ShareShare on XLinkedIn

1. The DNS Security Trio: How SPF, DKIM & DMARC Work Together

WeSecureX DNS Tools Directory providing domain verification and record lookup utilities
WeSecureX DNS Tools Directory providing domain verification and record lookup utilitiesWeSecureX Platform View

Preventing domain spoofing requires deploying all three email authentication standards together. Each protocol addresses a distinct vulnerability in the SMTP message delivery pipeline:

1. Sender Policy Framework (SPF - RFC 7208): SPF allows domain owners to publish a list of authorized IP addresses and server hostnames permitted to send email on behalf of their domain. When a mail transfer agent (MTA) receives an email, it inspects the sender's envelope Return-Path address, queries the domain's DNS for its SPF TXT record, and checks whether the sending server's IP address is listed. If the IP is unauthorized, the SPF check fails. However, SPF alone cannot protect against header spoofing because users only see the visible From: header in their email client, which SPF does not validate.

2. DomainKeys Identified Mail (DKIM - RFC 6376): DKIM adds an asymmetric cryptographic digital signature to every outgoing email. The sending mail server hashes specific email headers and the message body, encrypts the hash using a private key, and attaches the resulting signature inside the DKIM-Signature: header. The receiving mail server queries the sender's DNS for the corresponding public key published under a unique DKIM selector (e.g., google._domainkey.example.com). If the public key successfully decrypts the hash and matches the message content, the receiver knows with mathematical certainty that the email originated from your organization and was not altered in transit.

3. DMARC (RFC 7489): DMARC unites SPF and DKIM under a centralized policy enforcer. It requires Identifier Alignment, meaning the domain in the visible From: header must match the authenticated domain validated by SPF or DKIM. Most importantly, DMARC tells receiving mail servers what to do if an email fails authentication (p=none for monitoring, p=quarantine to route to spam, or p=reject to discard the message completely). Verify your current DNS records using our DNS Record Lookup Tool.

text
# Standard SPF TXT Record authorizing Google Workspace and SendGrid
# v=spf1 : Specifies protocol version
# include:_spf.google.com : Authorizes Google Workspace servers
# include:sendgrid.net : Authorizes SendGrid transactional email
# ~all : SoftFail unauthorized senders (migrate to -all for strict rejection)
v=spf1 include:_spf.google.com include:sendgrid.net ~all

# DMARC TXT Record published at _dmarc.example.com
# p=reject : Instructs receivers to discard unaligned or spoofed emails
# pct=100 : Applies policy to 100% of incoming emails
# rua=mailto:... : Sends daily aggregated XML authentication reports
v=DMARC1; p=reject; pct=100; rua=mailto:dmarc-reports@example.com; ruf=mailto:dmarc-forensics@example.com; aspf=r; adkim=r

2. Step-by-Step DNS Deployment & Phased DMARC Rollout

WeSecureX Security Headers Checker auditing email and web transport security
WeSecureX Security Headers Checker auditing email and web transport securityWeSecureX Platform View

Deploying email authentication across an enterprise without disrupting legitimate marketing, sales, and transactional emails requires a disciplined, phased rollout methodology. Jumping straight to a strict p=reject policy on day one can cause legitimate business communications to be blocked if third-party services (such as Zendesk, HubSpot, or billing platforms) were not properly authorized.

Phase 1: Comprehensive Asset Inventory (Week 1): Identify every internal and third-party service that sends email on behalf of your domain. Generate 2048-bit DKIM keys within each service console and publish the corresponding TXT/CNAME records in your DNS zone file. Construct an SPF record containing authorized include: directives, ensuring that the total number of DNS lookups does not exceed the strict RFC limit of 10 lookups.

Phase 2: Monitoring Mode with DMARC `p=none` (Weeks 2-4): Publish a DMARC record configured with p=none and configure an aggregate report mailbox (rua=mailto:dmarc@example.com). In this mode, receiving mail servers will not block any emails; instead, they will send daily XML reports detailing all servers sending email using your domain, their IP addresses, and their SPF/DKIM pass/fail rates. Analyze these reports to identify unauthorized shadow IT senders or misconfigured mail relays.

Phase 3: Quarantine Enforcement with DMARC `p=quarantine` (Weeks 5-6): Once all legitimate email senders consistently pass SPF and DKIM alignment, update your DMARC policy to p=quarantine. Spoofed emails failing authentication will now be diverted into the recipient's spam/junk folder rather than landing in the inbox.

Phase 4: Full Enforcement with DMARC `p=reject` (Week 7+): Advance the policy to p=reject. All receiving mail servers worldwide will immediately drop and reject spoofed emails at the SMTP boundary. Domain spoofing is now completely eradicated. You can monitor overall website and transport security using our Security Headers Checker.

DMARC Policy PhaseRecord Syntax ExampleAction on Authentication FailureRecommended Duration
Phase 1: Monitoringv=DMARC1; p=none; rua=mailto:dmarc@example.comNone; email is delivered normally to inbox; XML report dispatched2 to 4 weeks (audit all senders)
Phase 2: Partial Quarantinev=DMARC1; p=quarantine; pct=25; rua=mailto:...25% of failing emails routed to spam folder; remainder to inbox1 week (verify zero business disruption)
Phase 3: Full Quarantinev=DMARC1; p=quarantine; pct=100; rua=mailto:...100% of failing emails routed to spam/junk folder2 weeks (final verification)
Phase 4: Full Rejectionv=DMARC1; p=reject; pct=100; rua=mailto:...100% of spoofed emails rejected and discarded at SMTP connectionPermanent production posture

3. Automated DNS Security Auditing with WeSecureX

WeSecureX Website Scanner verifying DNS health, SPF lookups, and DMARC enforcement
WeSecureX Website Scanner verifying DNS health, SPF lookups, and DMARC enforcementWeSecureX Platform View

DNS configurations frequently suffer from silent degradation over time. Adding a new SaaS provider to an SPF record can inadvertently push the record over the 10-lookup limit, causing receiving servers to throw a permanent error (PermError) and reject all corporate emails. Similarly, forgetting to rotate DKIM cryptographic keys or publishing syntax typos in DNS TXT records leaves domains vulnerable to spoofing.

The WeSecureX DNS Record Lookup Tool and Website Security Scanner automatically query and validate your domain's complete DNS security posture. The scanner checks SPF lookup depth, validates DKIM key lengths (warning on weak 1024-bit keys), verifies DMARC policy enforcement status (p=reject), and checks for DNSSEC (Domain Name System Security Extensions) deployment to protect against DNS cache poisoning and man-in-the-middle attacks.

Ensure your corporate communications and domain reputation remain unblemished by auditing your records today with the DNS Record Lookup Tool, checking SSL certificate validity with the SSL Certificate Checker, and learning more about perimeter defense in our Essential Cybersecurity Best Practices Guide.

bash
# Inspecting DNS email authentication records via WeSecureX CLI
$ wesecurex dns --domain example.com --audit-email-security

[DNS] Querying authoritative nameservers for example.com...
[SPF] Found TXT record: v=spf1 include:_spf.google.com include:sendgrid.net -all
[SPF] Lookup Count: 4 / 10 allowed lookups [PASS]
[DKIM] Probing selector 'google._domainkey.example.com'...
[DKIM] 2048-bit RSA Public Key detected [PASS]
[DMARC] Found record at _dmarc.example.com: v=DMARC1; p=reject; pct=100; rua=mailto:reports@example.com
[DMARC] Policy: REJECT (100% of traffic protected) [PASS - MAXIMUM SECURITY]
[OVERALL] Email Spoofing Defense Score: 100/100 (Fully Compliant)

Apply it with WeSecureX

Add a hostname you own or are allowed to test, run a scan, and open the findings for that target. A confirmed result includes the request WeSecureX sent and the response the site returned, so you can reproduce it, fix it in your own application, and rescan the same host to confirm the issue is gone. WeSecureX is automated testing, not a manual penetration test, and a clean report is not a promise that every weakness is gone.

Checks that belong with this topic

  • Publish a single, consolidated SPF TXT record containing all authorized sending services.
  • Ensure SPF record requires fewer than 10 total DNS lookups.
  • Deploy 2048-bit RSA DKIM keys across all outgoing email providers.
  • Publish a DMARC record at `_dmarc.yourdomain.com` with an aggregate reporting address (`rua`).
  • Progressively advance DMARC policy from `p=none` to `p=quarantine` and finally `p=reject`.

Common Mistakes to Avoid

❌Exceeding the 10-DNS-lookup limit in the SPF record

Why it happens: Adding multiple `include:` mechanisms (Google, SendGrid, Salesforce, HubSpot) accumulates recursive DNS lookups.

Why it matters: RFC 7208 mandates that receivers abort SPF evaluation after 10 lookups, resulting in a `PermError` that causes legitimate emails to be marked as spam.

Correct approach: Flatten SPF records using automated tools or prune unused legacy marketing providers to stay comfortably below 10 lookups.

❌Leaving DMARC in monitoring mode (`p=none`) indefinitely

Why it happens: Teams publish a DMARC record to satisfy basic compliance checklists and never advance the policy to enforcement.

Why it matters: `p=none` provides zero protection against email spoofing; threat actors can spoof your domain with complete impunity.

Correct approach: Review aggregate reports and progressively migrate your policy from `p=none` to `p=quarantine` and ultimately `p=reject`.

❌Using weak 1024-bit RSA keys for DKIM instead of modern 2048-bit keys

Why it happens: Legacy mail software or DNS managers limit TXT string lengths, leading administrators to generate small keys.

Why it matters: 1024-bit RSA keys can be cracked using cloud computing clusters within a reasonable timeframe, allowing attackers to forge DKIM signatures.

Correct approach: Always generate 2048-bit RSA keys or modern Ed25519 keys for all DKIM selectors.

❌Publishing multiple SPF records for a single domain

Why it happens: Admins create a new TXT record for a new email service instead of editing the existing SPF string.

Why it matters: RFC 7208 specifies that a domain MUST NOT have more than one SPF record. Having multiple records causes immediate `PermError`.

Correct approach: Combine all authorized sending services into a single, unified `v=spf1 ...` TXT record.

Troubleshooting Guide

Problem: Legitimate marketing emails from Mailchimp or HubSpot are landing in customer spam folders

Possible Causes:

  • The marketing provider was not added to the SPF record or DKIM alignment failed.

How to verify: Inspect the raw email headers (`Authentication-Results`) in the recipient inbox for `spf=fail` or `dmarc=fail`.

How to fix: Configure custom domain DKIM authentication inside the marketing platform dashboard and add their `include:` mechanism to your SPF record.

Problem: DMARC reports indicate SPF fails on legitimate emails forwarded by users

Possible Causes:

  • Email forwarding breaks SPF because the forwarding server's IP does not match the original sender's SPF record.

How to verify: Inspect aggregate XML reports for forwarding MTA IPs failing SPF but passing DKIM.

How to fix: This is expected behavior. As long as DKIM signatures remain intact and align with the `From:` domain, DMARC will pass.

Problem: DNS management interface rejects a 2048-bit DKIM key due to length limitations

Possible Causes:

  • Standard DNS TXT records have a 255-character limit per single string token.

How to verify: Check if the DNS provider allows splitting the key into multiple quoted strings `("part1" "part2")`.

How to fix: Split the long base64 key string into two 255-character chunks within the same TXT record, or use CNAME-based DKIM delegation.

Actionable Checklist

WeSecureX Platform · Surface Monitor

Application Attack Surface Analyzer

Inspect open ports, TLS certificate chains, HTTP headers, and API endpoint security posture.

Includes: TLS/SSL cipher suite & expiration monitoring · Security header verification (CSP, HSTS) · Subdomain asset discovery

Frequently Asked Questions

Not if you follow a phased rollout. By starting with `p=none` and analyzing aggregate XML reports for 2-4 weeks, you can identify and authorize every legitimate email service before enforcing `p=reject`.

BIMI is a modern email standard that displays your verified company logo next to incoming emails in supported inboxes (like Gmail and Apple Mail). BIMI strictly requires an active DMARC policy of `p=quarantine` or `p=reject`.

No. The SPF specification explicitly forbids multiple SPF TXT records. If more than one record is present, receiving mail servers will throw a `PermError` and reject or quarantine your messages.

Authoritative Sources & References

  • RFC 7489: Domain-based Message Authentication, Reporting, and Conformance (DMARC)IETF (official)
    View Source
  • Google Workspace & Yahoo Email Sender Guidelines (2024-2026)Google (official)
    View Source

Continue exploring related technical architecture and defensive guides

Security Research & Engineering Articles

All articles