ShieldX Toolly
Open a tool Donate
Home Home
Blog Blog
FAQ FAQ
Open a tool Donate
Back to cheatsheets
Web Security

DMARC, SPF & DKIM Setup

Email authentication DNS records to prevent spoofing — SPF, DKIM, and DMARC with deployment order.

3 snippets Intermediate dmarc-spf-dkim-checker
DMARCSPFDKIMemail spoofingDNS

What you'll learn

  • SPF record
  • DKIM record
  • DMARC record

How to use these snippets

  1. Click the Copy button next to any snippet to copy it to your clipboard.
  2. Paste the code into your project, IDE, or terminal.
  3. Replace placeholder values (like example.com or your-secret) with your actual data.
  4. Review the code comments for important security notes and caveats.
  5. Try the interactive related tool to see the concept in action.
Code Snippets

Copy-paste code snippets

3 ready-to-use snippets for dmarc, spf & dkim setup. Click copy and paste into your project.

SPF record
                # SPF — authorize sending IPs
example.com.  TXT  "v=spf1 ip4:192.0.2.0/24 include:_spf.google.com ~all"

# ~all = softfail (mark but accept)
# -all = hardfail (reject)
# +all = PASS everyone (NEVER use)
# Warning: 10 DNS lookup limit per include
              
DKIM record
                # DKIM public key in DNS
selector1._domainkey.example.com.  TXT  \
  "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQE..."

# Generate DKIM key pair
openssl genrsa -out dkim.private 2048
openssl rsa -in dkim.private -pubout -outform der 2>/dev/null | \
  openssl base64 -A
              
DMARC record
                # DMARC — tie SPF + DKIM with policy
_dmarc.example.com.  TXT  \
  "v=DMARC1; p=reject; rua=mailto:dmarc@example.com; \
  ruf=mailto:dmarc@example.com; adkim=s; aspf=s; pct=100"

# Deployment order:
# 1. p=none   — monitor only, review reports
# 2. p=quarantine — failed emails → spam
# 3. p=reject — failed emails blocked
              
Tool

Try this concept hands-on with the interactive tool.

100% Free · No signup · No cost

Generate something unguessable right now

148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.

Open the toolkit

Part of the Toolly ecosystem · secure.toolly.site