Email for your domain, with DNS setup handled. PostScale

    Email Security with SPF, DKIM, and DMARC

    9 min readIntermediate

    Quick answer

    SPF authorizes sending hosts, DKIM signs mail, and DMARC checks alignment with the visible From domain. Configure each legitimate sender, inspect received messages and reports, then choose an enforcement policy. DNS publication alone does not activate signing or prove delivery.

    What you'll learn
    • Understand authentication, domain alignment and the limits of spoofing protection
    • Configure SPF, DKIM, and DMARC DNS records using the DNScale dashboard and API
    • Follow best practices for phased DMARC rollout from monitoring to enforcement
    • Test and validate your email authentication setup using command-line and online tools

    Email spoofing allows attackers to send messages that appear to come from your domain. Without proper authentication, anyone can send an email claiming to be from ceo@yourdomain.com. SPF, DKIM, and DMARC are DNS-based standards that help receiving mail servers verify legitimate emails. All three rely on TXT records published in your DNS zone, making proper DNS configuration essential.

    This is the pillar guide for the full stack. For focused implementation details, use the dedicated pages:

    Adding Postscale to an existing domain

    Use the Postscale DNS review and approval walkthrough for the actual setup sequence: merge compatible SPF, preserve DMARC, add the supplied DKIM selector and review the record changes. Application sending keeps your existing receiving MX. Personal forwarding is a separate receiving cutover.

    What You'll Learn

    • How SPF declares authorized mail servers
    • How DKIM cryptographically signs emails
    • How DMARC defines policies for failed authentication
    • Setting up all three via DNScale dashboard and API
    • Testing and validating your configuration

    SPF (Sender Policy Framework)

    What SPF Does

    SPF lets you specify which IP addresses and mail servers can send email for your domain. Receiving servers check your SPF record to verify the sender is authorized. SPF records are published as TXT records at the envelope-sender domain (or the HELO identity when applicable), so understanding how DNS works is helpful context.

    For a deeper standalone walkthrough, see SPF record explained.

    SPF Record Syntax

    An SPF record is a TXT record at the domain being evaluated:

    v=spf1 [mechanisms] [qualifier]all
    ComponentDescription
    v=spf1Version identifier (required)
    include:domainAllow servers authorized by another domain's SPF
    aAllow the domain's A record IP
    mxAllow the domain's MX servers
    ip4:x.x.x.xAllow a specific IPv4 address or range
    ip6:x::xAllow a specific IPv6 address or range
    ~allSoft fail for unauthorized senders
    -allHard fail for unauthorized senders

    Common SPF Examples

    Google Workspace:

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

    Microsoft 365:

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

    Multiple providers:

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

    Custom mail server:

    v=spf1 ip4:203.0.113.5 mx ~all

    SPF Best Practices

    1. Start with ~all (soft fail), move to -all after testing
    2. Keep within the 10 DNS-querying-term limit, including nested policies
    3. Include all sending sources: transactional email, marketing platforms, etc.
    4. If you use multiple mail services, verify each one is covered before enforcing -all

    SPF alone does not prevent spoofing of the visible "From" header. It only validates the envelope sender. Combine it with DKIM and DMARC for comprehensive protection.


    DKIM (DomainKeys Identified Mail)

    What DKIM Does

    DKIM adds a digital signature to outgoing emails. Your mail server signs each email with a private key, and you publish the corresponding public key in DNS. Receiving servers use this public key to verify that the signed content was not modified and that the signer controls the corresponding domain key. Like SPF, the public key is stored as a TXT record.

    For selectors, key rotation, and DNS key formatting, see DKIM explained.

    How DKIM Works

    1. Your mail server generates a cryptographic signature using a private key
    2. The signature is added to the email's headers
    3. Receiving servers look up your DKIM public key in DNS
    4. They verify the signature matches the email content
    5. If valid, the email passes DKIM authentication

    DKIM Record Syntax

    A DKIM record is a TXT record at selector._domainkey.yourdomain.com:

    selector._domainkey.yourdomain.com.  TXT  "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
    Response reference
    TagDescription
    v=DKIM1Version identifier
    k=rsaKey type (usually RSA)
    p=...Public key (base64 encoded)
    t=sOptional: DKIM i= identity domain must match the signing d= domain; this is not DMARC strict alignment
    t=y(Optional) Testing mode

    DKIM Selectors

    The selector is a name that identifies which key to use. This allows:

    • Low-disruption key rotation
    • Different keys for different mail services
    • Multiple keys active simultaneously

    Common selector patterns:

    • google for Google Workspace
    • selector1, selector2 for Microsoft 365
    • k1, k2, k3 for custom setups
    • mailjet, sendgrid for third-party services

    Getting Your DKIM Keys

    DKIM keys are generated by your email provider. Here's where to find them:

    Google Workspace:

    1. Admin Console → Apps → Google Workspace → Gmail
    2. Authenticate email → Generate new record
    3. Publish the supplied TXT value, then enable authentication in Google Workspace

    Microsoft 365:

    1. Microsoft 365 Defender → Email & collaboration → Policies
    2. DKIM → Select domain → Create DKIM keys
    3. Publish the two supplied CNAME records, then enable DKIM signing

    Third-party services (SendGrid, Mailjet, etc.):

    • Check your provider's dashboard for DNS settings
    • They'll provide the selector name and public key

    DKIM Record Examples

    Google Workspace:

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

    Microsoft 365: publish CNAME, not TXT, at selector1._domainkey and selector2._domainkey. Copy the exact tenant-specific targets from Microsoft's DKIM configuration. Do not construct targets from an example; their format depends on the tenant.

    Custom/Third-party:

    mail._domainkey.yourdomain.com.  TXT  "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3..."

    DKIM Best Practices

    1. Use 2048-bit keys - 1024-bit keys are increasingly vulnerable
    2. Rotate keys periodically - At least annually for security
    3. Keep private keys secure - Never expose them in DNS or logs
    4. Use unique selectors - Different selectors for each service
    5. Test before enforcing DMARC - Ensure DKIM passes before p=reject

    DKIM key rotation is conceptually similar to DNSSEC key rollover. In both cases, you must publish the new key before removing the old one to avoid validation failures during the transition.


    DMARC (Domain-based Message Authentication)

    What DMARC Does

    DMARC builds on SPF (and DKIM) to provide:

    • Alignment of an authenticated SPF or DKIM domain with the visible From domain
    • A requested policy for messages that fail that alignment
    • Reporting so you can monitor authentication results

    DMARC is a critical layer in DNS security best practices because, when deployed at enforcement and honored by receivers, it reduces direct domain spoofing in phishing campaigns.

    For alignment, reporting, and rollout details, see DMARC explained.

    DMARC Record Syntax

    A DMARC record is a TXT record at _dmarc.yourdomain.com:

    v=DMARC1; p=policy; [optional tags]

    Required Tags:

    TagDescription
    v=DMARC1Version identifier
    p=none|quarantine|rejectPolicy for failed emails

    Optional Tags:

    TagDescription
    rua=mailto:addressAggregate report destination
    ruf=mailto:addressForensic report destination
    adkim=s / aspf=sOptional strict alignment; relaxed alignment is the default
    sp=policySubdomain policy

    DMARC Policy Options

    PolicyActionWhen to Use
    p=noneRequest monitoringInitial setup
    p=quarantineRequest quarantineAfter investigating legitimate failures
    p=rejectRequest rejectionAfter validating legitimate mail streams

    DMARC Examples

    Monitor mode:

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

    Quarantine mode:

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

    Reject mode:

    v=DMARC1; p=reject; rua=mailto:dmarc-reports@yourdomain.com
    1. Inventory legitimate senders and begin with p=none if no policy exists.
    2. Review reports over a representative sending cycle and repair failing streams.
    3. Move to p=quarantine, then p=reject when the evidence supports it.

    RFC 9989 removed pct; do not depend on percentage-based rollout. Keep a working existing policy when adding another sender.

    Be patient with the rollout. Rushing to p=reject before verifying all legitimate sending sources are covered can cause real business email to be blocked. Review your DMARC aggregate reports carefully at each stage.


    Setup via DNScale Dashboard

    Before adding records, review the existing zone. Edit an existing SPF policy instead of creating a second one; preserve unrelated TXT records and working DKIM selectors. The examples below are placeholders for a new configuration.

    Create SPF Record

    1. Log in at dnscale.eu
    2. Select your domain
    3. Click Add Record
    4. Configure:
      • Name: Leave empty (apex)
      • Type: TXT
      • Content: v=spf1 include:_spf.google.com ~all
      • TTL: 3600
    5. Click Create Record

    Create DKIM Record

    1. Get your DKIM public key from your email provider (see "Getting Your DKIM Keys" above)
    2. Click Add Record
    3. Configure:
      • Name: google._domainkey (or your provider's selector)
      • Type: TXT
      • Content: v=DKIM1; k=rsa; p=MIIBIjANBgkq... (your public key)
      • TTL: 3600
    4. Click Create Record

    For Microsoft 365, use the provider-supplied CNAME records for both selectors instead of the TXT example. Publishing DNS is followed by enabling signing at the mail provider.

    Create DMARC Record

    1. Click Add Record
    2. Configure:
      • Name: _dmarc
      • Type: TXT
      • Content: v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com
      • TTL: 3600
    3. Click Create Record

    Setting sensible TTL values on email authentication records matters. Use 3600 seconds (1 hour) as a baseline. See our TTL best practices guide for recommendations.


    Setup via DNScale API

    Authentication

    export DNSCALE_API_KEY="your-api-key"

    Get Zone ID

    curl -s "https://api.dnscale.eu/v1/zones" \
      -H "Authorization: Bearer $DNSCALE_API_KEY" | jq '.data.zones[] | {id, name}'

    Create SPF Record

    curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer $DNSCALE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "@",
        "type": "TXT",
        "content": "v=spf1 include:_spf.google.com ~all",
        "ttl": 3600
      }'

    Create DKIM Record

    curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer $DNSCALE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "google._domainkey",
        "type": "TXT",
        "content": "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...",
        "ttl": 3600
      }'

    Replace google._domainkey with your selector and the public key with your actual DKIM key.

    Create DMARC Record

    curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer $DNSCALE_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "_dmarc",
        "type": "TXT",
        "content": "v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com",
        "ttl": 3600
      }'

    Verify Records

    curl -s "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
      -H "Authorization: Bearer $DNSCALE_API_KEY" | jq '.data.records[] | select(.type == "TXT")'

    If you manage DNS as code, you can also deploy email authentication records through Terraform or DNSControl, or even set up multi-provider DNS to keep your email records synchronized across providers.


    The SPF standard defines the evaluation limits; DMARC's current specification defines alignment and requested receiver policy. These checks reduce direct domain spoofing, but do not prevent display-name or lookalike-domain attacks.

    Testing and Validation

    Online Tools

    Command Line

    # Check SPF
    dig TXT yourdomain.com +short
     
    # Check DKIM (replace 'google' with your selector)
    dig TXT google._domainkey.yourdomain.com +short
     
    # Check DMARC
    dig TXT _dmarc.yourdomain.com +short

    If changes aren't appearing, review how DNS propagation works and consider flushing your local DNS cache.

    Send a Test Email

    After enabling signing, send to an inbox you control and inspect its trusted Authentication-Results headers. DNS lookups alone cannot establish delivery:

    1. Send an email to a Gmail account
    2. Open the email → Click the three dots → "Show original"
    3. Look for:
      • spf=pass
      • dkim=pass
      • dmarc=pass
    4. Compare the authenticated domains with the visible From domain; retain a redacted copy of the received headers for diagnosis.
    5. Confirm actual receipt and test existing inbound mail separately.

    How Email Authentication Fits Into Broader DNS Security

    SPF, DKIM, and DMARC are part of a wider set of DNS-based security mechanisms. Consider pairing them with:

    Together, these records create a layered defence that protects both your domain's email and web traffic.


    Summary

    Scroll horizontally to see all columns →

    RecordNameTypeExample
    SPF@TXTv=spf1 include:_spf.google.com ~all
    DKIMselector._domainkeyTXTv=DKIM1; k=rsa; p=MIIBIjAN...
    DMARC_dmarcTXTv=DMARC1; p=none; rua=mailto:dmarc@example.com

    How They Work Together:

    • SPF verifies the sending server is authorized
    • DKIM verifies the email content wasn't modified
    • DMARC combines authentication with visible-From alignment and a requested failure policy

    Recommended Implementation Order:

    1. Set up SPF first (easiest)
    2. Configure DKIM with your email provider
    3. Add DMARC in monitor mode (p=none)
    4. Review reports, fix issues
    5. Gradually enforce DMARC (p=quarantine → p=reject)

    Frequently asked questions

    Do I need all three of SPF, DKIM, and DMARC?
    Configure all three for your sending domain. DMARC passes when SPF or DKIM passes with an identifier aligned to the visible From domain. One failing mechanism does not automatically mean DMARC fails.
    What does the SPF +all and -all difference mean?
    '+all' authorizes every host, '~all' produces softfail, and '-all' produces fail for unmatched hosts. Receivers decide how to handle those results. Inventory all legitimate senders before tightening a policy.
    Why is my SPF record failing 'too many DNS lookups'?
    The limit covers 10 evaluated DNS-querying SPF terms, including nested includes. Remove unused services and follow provider guidance. Manual flattening needs continuous maintenance as provider IP ranges change.
    How do I generate a DKIM key pair?
    Your email-sending platform (Google Workspace, Microsoft 365, Postmark, SES, etc.) generates the key pair for you. They give you the public key to publish as a TXT record in DNS at <selector>._domainkey.<your-domain>; they keep the private key and sign outgoing mail with it. Rotate at least annually.
    What does p=quarantine vs p=reject mean in DMARC?
    These request treatment for mail that fails DMARC alignment: quarantine or rejection. Receiver policy still controls delivery. Investigate legitimate failing streams before changing enforcement.

    Related guides

    Check your email authentication records

    Start with the published policy, then use the email guides to interpret and correct it.

    Validate email DNS