DevSecOps guide 7 min read Updated

Email security as code: automating MX, SPF, DKIM, DMARC and MTA-STS checks

Stop routine SaaS and DNS edits from breaking the 10-lookup SPF limit, downgrading DMARC or stalling inbox delivery.

For DevSecOps, platform and email engineering teams
Short answer

Email security as code treats MX, SPF, DKIM, DMARC, MTA-STS and TLS-RPT records as continuously tested pipeline invariants. Calling middle.network email endpoints in CI/CD and nightly jobs catches SPF 10-lookup overflows (RFC 7208), weak DMARC policies (p=none), broken MTA-STS policies and IP blocklist hits before transactional mail bounces or spoofing succeeds.

Who it is for
DevSecOps, platform and product teams running transactional email (auth codes, invoices, alerts) alongside corporate mail.
What it covers
Automated checks across every email auth and transport standard plus weighted 0-100 scoring and DNSBL reputation.
Why it matters
Adding one marketing or CRM tool often pushes SPF past 10 DNS lookups (silent permerror) or leaves DMARC unenforced.
How to integrate
Call our email-score, spf, dmarc, mx, mta-sts and blacklist endpoints on DNS PRs and a daily schedule.
Score a domain’s email authentication right now

See how our recursive SPF lookup counter and 0-100 email grade inspect your domain in seconds.

Why transactional and corporate email breaks silently

Unlike an HTTP 500 error, a broken SPF record or misconfigured DMARC alignment rarely pages on-call. Password resets, invoices and security alerts simply start landing in Gmail, Yahoo and Outlook spam folders - or attackers spoof your domain because DMARC stayed at p=none.

Major inbox providers enforce strict SPF, DKIM and DMARC alignment for bulk and transactional senders. Checking records once a year fails when marketing, billing and engineering teams edit DNS every month.

ProtocolCyber risk / delivery failure preventedTarget baseline for CI gate
SPF (RFC 7208)Permerror (>10 DNS lookups), duplicate SPF TXT records, dangerous +all.Single record, <= 10 lookups (warn at 9), ends in -all or ~all.
DKIM (RFC 6376)Unsigned transactional mail or expired/revoked selector keys.Valid 2048-bit public key published for every active sending service.
DMARC (RFC 7489)Direct From-address spoofing and brand phishing.p=quarantine or p=reject with monitored rua aggregate report mailbox.
MX & FCrDNSSingle point of failure mail routing or missing reverse PTR on sending IPs.Redundant MX hosts and forward-confirmed reverse DNS.
MTA-STS & TLS-RPTSilent downgrade of server-to-server email from TLS to cleartext.Valid HTTPS policy file in enforce mode plus TLS-RPT reporting record.

How to enforce a minimum email score and SPF ceiling in CI

One API call to our email-score tool runs live checks across MX, SPF, DKIM, DMARC, BIMI, MTA-STS and TLS-RPT simultaneously, returning a weighted 0-100 score (A+ to F) alongside ranked copy-ready fixes. Pair it with our SPF check (which expands the full nested include tree) and canary-verified blacklist check for complete coverage.

Automated email security gate (GitHub Actions / shell)
# .github/workflows/email-security-gate.yml
name: Email Security Gate
on:
  push:
    paths: ['dns/**', 'terraform/dns/**']
  schedule:
    - cron: '0 6 * * *' # daily posture check at 06:00 UTC
jobs:
  email-gate:
    runs-on: ubuntu-latest
    steps:
      - name: Check email score, SPF lookup budget and DMARC
        env:
          MN_API_KEY: ${{ secrets.MN_API_KEY }}
          DOMAIN: example.com
        run: |
          score_json=$(curl -sS -X POST "https://api.middle.network/v1/tools/email-score" \
            -H "Authorization: Bearer $MN_API_KEY" -H "Content-Type: application/json" \
            -d "{\"input\":{\"domain\":\"$DOMAIN\"}}")
          score=$(echo "$score_json" | jq -r '.data.score // 0')
          echo "Email score: $score/100 - $(echo "$score_json" | jq -r '.summary.plain')"

          spf_json=$(curl -sS -X POST "https://api.middle.network/v1/tools/spf" \
            -H "Authorization: Bearer $MN_API_KEY" -H "Content-Type: application/json" \
            -d "{\"input\":{\"domain\":\"$DOMAIN\"}}")
          lookups=$(echo "$spf_json" | jq -r '.data.lookups // 0')
          echo "SPF DNS lookups: $lookups/10"

          if [ "$score" -lt 80 ] || [ "$lookups" -gt 10 ]; then
            echo "Email security gate failed."
            exit 1
          fi
# Inspect the full nested SPF include tree and exact lookup count
curl -sS -X POST "https://api.middle.network/v1/tools/spf" \
  -H "Authorization: Bearer $MN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input":{"domain":"example.com"}}' | jq '{status, lookups: .data.lookups, plain: .summary.plain, findings}'
Watch the 9/10 SPF lookup cliff
Because nested third-party includes can add new lookups without warning, treat 9 out of 10 SPF lookups as a pipeline warning. One upstream vendor change can silently push 9 to 11 and break SPF across every receiver.

Closing the loop on sub-domains and parked domains

Enforce email security as code across every domain your organisation owns, not just the primary apex. Transactional subdomains (such as mail.example.com or auth.example.com) need their own verified SPF and DKIM alignment, while parked domains should be pinned to v=spf1 -all and DMARC p=reject so attackers cannot abuse unused brand names.

How middle.network turns email authentication into a real CI invariant

Basic SPF checkers only read the top-level TXT string and miss hidden vendor includes three levels deep. middle.network recursively expands the entire SPF include tree, evaluates all seven email-trust standards simultaneously in one weighted 0-100 score, and self-tests DNSBL zones hourly so reputation checks stay honest.

Full nested SPF tree math

Counts every DNS-triggering mechanism across nested includes so you catch the 9/10 and 10/10 RFC 7208 cliff before mail bounces.

Impact-weighted scoring

email-score weights real spoofing enforcement (DMARC, SPF, DKIM) above optional enhancements and returns ranked copy-ready fixes.

Verified blocklist answers

Canary-checked DNSBL queries refuse to report "clean" when a blocklist rejects cloud resolvers.

Questions people ask

What is a good email-score threshold for a CI/CD gate?
80 or higher (grade B or above) confirms that core inbox authentication requirements (MX, SPF, DKIM and DMARC) are in place. High-security organisations typically gate at 90+ with DMARC at p=reject and MTA-STS enforced.
Why does SPF fail after 10 DNS lookups?
RFC 7208 caps SPF evaluation at 10 mechanisms that trigger DNS lookups (include, a, mx, ptr, exists, redirect) to prevent DNS amplification. Exceeding 10 causes receivers to return permerror and treat SPF as failed.
Can I check a specific DKIM selector via the API?
Yes. Pass {"domain": "example.com", "selector": "selector1"} to the DKIM API endpoint to verify each sending service selector individually.
Does bulk-sender check Gmail, Yahoo and Microsoft sender requirements?
Yes. The bulk-sender check evaluates SPF, DKIM, DMARC, forward-confirmed reverse DNS and alignment rules required by major inbox providers.
How do these checks support ISO 27001 and SOC 2 audits?
SPF, DKIM and DMARC evidence ISO/IEC 27001:2022 A.5.14 (Information transfer) and SOC 2 CC6.6; MTA-STS and TLS-RPT evidence A.8.24 (Cryptography) and CC6.7.

Sources and further reading

Written by the middle.network engineering team (Middle Enterprises Pty Ltd, ABN 88 633 909 412), who build and operate these tools. Last reviewed 2026-11-27.