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.
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.
| Protocol | Cyber risk / delivery failure prevented | Target 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 & FCrDNS | Single point of failure mail routing or missing reverse PTR on sending IPs. | Redundant MX hosts and forward-confirmed reverse DNS. |
| MTA-STS & TLS-RPT | Silent 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.
# .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}'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.
Counts every DNS-triggering mechanism across nested includes so you catch the 9/10 and 10/10 RFC 7208 cliff before mail bounces.
email-score weights real spoofing enforcement (DMARC, SPF, DKIM) above optional enhancements and returns ranked copy-ready fixes.
Canary-checked DNSBL queries refuse to report "clean" when a blocklist rejects cloud resolvers.
Questions people ask
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.