How to Monitor Sending Domain Health — 2 Mail Metrics for Publisher Records
Check the sending domain's mail-service status and published DNS records on a daily schedule. Emit both as metrics, compare them with the intended configuration, and alert on disagreement. For a media product that lets customers point their own domains at a publication, the useful question is whether today's records still match what the publisher approved.
Short answer: monitor agreement between intent, published records, and mail readiness. A green verification badge alone is incomplete evidence. So is a successful DNS lookup.
Keep the evidence.
A daily check suits configuration that should never change on its own. It can expose a record edited by hand last month without making every missing domain an incident. Start with the active publication inventory: retired domains should leave the monitoring set deliberately. Onboarding may need a faster feedback loop; the daily audit serves the quieter period after activation.
How should we monitor sending domain health with records and mail status metrics?
Before: a publisher finishes setup, the mail status turns green, and that badge becomes the team's permanent explanation of domain health.
After: an approved record set describes intent. A DNS observation describes publication. A mail-service observation describes acceptance. The monitor preserves both observations, so an operator can explain which one changed.
Diagram in words: active publisher inventory → approved sending records → DNS and mail observations → two readiness metrics → disagreement event. A failed collection takes a separate path to a check-error event. Retirement takes another path out of the monitored inventory.
The difference matters during investigation. If the mail service still reports readiness but the required record has changed, “verified” hides the drift. If records match but the service reports that the domain is unready, another DNS edit may be the wrong response. Put the two signals beside each other and keep the missing-record details in the event log. A single red badge throws away that distinction just when someone needs it.
Use two binary readiness metrics: DNS matches approved intent, and mail reports ready. Compute disagreement from those values. There is one extra policy decision: two zeros agree numerically, but an active publication expected to be ready still needs attention. The example therefore alerts on disagreement or on a readiness violation for an active domain. Absence alone is not its alert rule.
This is configuration monitoring. It does not establish inbox placement or delivery.
Step 1 — Run a small, explicit reconciliation example
Save the following as publisher-health.ts and execute it with a TypeScript-capable Node.js runner. It needs no third-party imports. The default input is an illustrative snapshot, with one expected TXT record missing and mail readiness still true. The record content is test data, not a DNS configuration to publish.
These are application-owned fields. They don't assert any vendor's response schema. Your collection adapter must translate the actual DNS and mail responses into this shape before the reconciliation runs. That boundary makes the example copyable without inventing request parameters or parsing undocumented mail-status values. The optional authenticated branch reads both sources as opaque evidence; it does not pretend that fetching them implements the adapter.
import { readFile } from "node:fs/promises"; type SendingRecord = { name: string; type: string; value: string }; type Snapshot = { domain: string; active: boolean; expectedReady: boolean; observedAt: string; expected: SendingRecord[]; published: SendingRecord[]; mailReady: boolean; }; function validate(input: unknown): Snapshot { if (typeof input !== "object" || input === null) { throw new Error("Snapshot must be an object"); } const s = input as Snapshot; const records = (value: unknown): value is SendingRecord[] => Array.isArray(value) && value.every((r) => typeof r === "object" && r !== null && typeof r.name === "string" && r.name.length > 0 && typeof r.type === "string" && r.type.length > 0 && typeof r.value === "string" ); if ( typeof s.domain !== "string" || s.domain.length === 0 || typeof s.active !== "boolean" || typeof s.expectedReady !== "boolean" || typeof s.mailReady !== "boolean" || typeof s.observedAt !== "string" || !Number.isFinite(Date.parse(s.observedAt)) || !records(s.expected) || s.expected.length === 0 || !records(s.published) ) throw new Error("Invalid normalized snapshot"); return s; } function reconcile(s: Snapshot) { if (!s.active) return { event: "domain_retired", domain: s.domain }; const ageMs = Date.now() - Date.parse(s.observedAt); if (ageMs < 0 || ageMs > 26 * 60 * 60 * 1000) { throw new Error("Observation is stale or dated in the future"); } const owner = (name: string) => name.toLowerCase().replace(/\.$/, ""); const missing = s.expected.filter((wanted) => !s.published.some((found) => owner(wanted.name) === owner(found.name) && wanted.type.toUpperCase() === found.type.toUpperCase() && wanted.value === found.value ) ); const dnsReady = missing.length === 0; const disagreement = dnsReady !== s.mailReady; return { event: "sending_domain_observed", domain: s.domain, observedAt: s.observedAt, metrics: { sending_dns_matches_intent: Number(dnsReady), sending_mail_ready: Number(s.mailReady) }, disagreement, alert: disagreement || (s.expectedReady && (!dnsReady || !s.mailReady)), missing }; } async function readEvidence(base: string, path: string, key: string) { for (let attempt = 0; attempt < 4; attempt += 1) { const response = await fetch(base + path, { method: "GET", headers: { Authorization: "Bearer " + key }, signal: AbortSignal.timeout(10_000) }); if (response.status === 429 && attempt < 3) { const retryAfter = response.headers.get("Retry-After"); const seconds = retryAfter === null ? NaN : Number(retryAfter); const retryAt = retryAfter === null ? NaN : Date.parse(retryAfter); const requestedMs = Number.isFinite(seconds) ? seconds * 1000 : retryAt - Date.now(); const delayMs = Math.max( 1000 * 2 ** attempt, Number.isFinite(requestedMs) ? requestedMs : 0 ); await response.body?.cancel(); await new Promise((resolve) => setTimeout(resolve, delayMs)); continue; } if (!response.ok) { throw new Error("Evidence read failed: " + response.status + " " + await response.text()); } return await response.json() as unknown; } throw new Error("Evidence retry budget exhausted"); } async function run() { try { const file = process.env.SNAPSHOT_FILE; const input: unknown = file ? JSON.parse(await readFile(file, "utf8")) : { domain: "news.publisher.example", active: true, expectedReady: true, observedAt: new Date().toISOString(), expected: [{ name: "selector._domainkey.news.publisher.example", type: "TXT", value: "illustrative-approved-value" }], published: [], mailReady: true }; const snapshot = validate(input); const key = process.env.INFRAI_API_KEY; const baseUrl = process.env.INFRAI_BASE_URL; if (key || baseUrl) { if (!key || !baseUrl || !file) { throw new Error("Authenticated mode needs key, base URL, and snapshot file"); } const base = baseUrl.replace(/\/$/, ""); if (!base.startsWith("https://") || !base.endsWith("/v1")) { throw new Error("Use the documented HTTPS v1 API base URL"); } if (snapshot.active) { const [records, mailStatus] = await Promise.all([ readEvidence(base, "/dns/record/list", key), readEvidence(base, "/email/domain/get/" + encodeURIComponent(snapshot.domain), key) ]); console.log(JSON.stringify({ event: "raw_sending_evidence", domain: snapshot.domain, collectedAt: new Date().toISOString(), records, mailStatus })); } } console.log(JSON.stringify({ mode: file ? "snapshot" : "demonstration", result: reconcile(snapshot) })); return true; } catch (error: unknown) { console.error(JSON.stringify({ event: "sending_domain_check_error", message: error instanceof Error ? error.message : String(error) })); return false; } } async function main() { const watch = process.env.WATCH === "1"; if (watch && !process.env.SNAPSHOT_FILE) { throw new Error("Scheduled mode requires SNAPSHOT_FILE"); } const passed = await run(); if (!watch) { if (!passed) process.exitCode = 1; return; } const dayMs = 24 * 60 * 60 * 1000; const tick = async () => { await run(); setTimeout(() => { void tick(); }, dayMs); }; setTimeout(() => { void tick(); }, dayMs); } main().catch((error: unknown) => { console.error(JSON.stringify({ event: "sending_domain_monitor_error", message: error instanceof Error ? error.message : String(error) })); process.exitCode = 1; }); The default result should contain DNS readiness of 0, mail readiness of 1, and alert: true. Copy the expected record into the published array and rerun: both metrics should become 1, with no alert. Change active to false and the result should be a retirement event with no readiness metrics. Those three inputs explain the policy more clearly than another paragraph about “healthy” domains.
To enable authenticated collection, supply INFRAI_API_KEY and set INFRAI_BASE_URL to the provider's documented HTTPS API base ending in /v1, along with your snapshot file. These read-only requests emit a raw evidence event. They deliberately leave the normalized snapshot unchanged: implement the documented response mapping before treating this branch as an automated collector. Keep raw record evidence in an access-controlled log destination. The trade-off is explicit: this example gives you runnable collection and reconciliation, while your adapter remains responsible for joining them correctly.
Record values remain exact. Owner-name case and a trailing dot are normalized, but TXT content is not lowercased. Normalize the integration's TXT representation before producing the snapshot; this comparator deliberately checks approved values rather than attempting a general DNS parser. Extra records are allowed because the customer's domain can serve purposes beyond this publication.
Step 2 — Schedule fresh evidence and retain the two metrics
For real observations, set SNAPSHOT_FILE to a file containing the application-owned structure above. Set WATCH to 1 to run immediately and repeat 24 hours after each completed evaluation. The file must be refreshed by your collector before each run. A repeated evaluation of yesterday's evidence is not a new observation, so the timestamp belongs to collection time, not evaluation time.
The 26-hour freshness allowance is an example policy, chosen to leave two hours beyond a daily interval. Adjust it deliberately. Collection errors should produce the check-error event and leave readiness unknown; converting a timeout into an empty record array would falsely describe missing records. Likewise, a missing input file is a collection problem, not evidence that the publisher retired its domain.
The timer demonstrates cadence in one running process. A production scheduler should invoke a single run and provide the execution history your operators need, because this timer does not survive process termination or recover missed executions. Keep collection and evaluation ordered. The sample waits for one evaluation to finish before scheduling another.
Export the two numeric fields to your metrics system through its documented ingestion mechanism. The code emits structured log output; it does not secretly upload metrics or configure an alerting service. Preserve observedAt, domain, and missing-record details as investigation evidence, and configure the alert rule from the emitted disagreement and readiness policy. Keep a separate alert for stale collection. Otherwise a broken collector can leave an old green result looking current.
Choose integration ownership before adding more glue:
| Option | Where to evaluate it | Boundary for this publisher audit |
|---|---|---|
| Cloudflare for SaaS | Customer-domain onboarding for the publication | Treat customer-domain acceptance and sending-mail readiness as separate observations. Keep the approved sending records in the audit. |
| Amazon Route 53 | The DNS side of an AWS-oriented implementation | Pair record observations with a mail-service observation; DNS alone cannot express the two-signal rule. |
| DNSimple | A domain-focused DNS integration | Check its record representation against the adapter contract, and assign ownership for scheduling and mail-status collection. |
| Unified backend API | DNS, mail, scheduling, and telemetry accessed through a shared platform | Evaluate the documented schemas and retain an application-owned definition of agreement. A shared interface does not choose the publisher's alert policy. |
Infrai offers one API, one key, and one bill: a simple REST API with no SDK required and broad backend coverage. Shared credentials reduce handoffs between the publisher's DNS and mail collectors, while unified billing reduces invoice reconciliation. The plain REST interface is language-agnostic: use any HTTP client. For this collector, that means the same request mechanism reads DNS and mail evidence instead of introducing a separate SDK dependency for each observation. The platform covers 295 routes across 20 modules. Its self-describing API provides public discovery with no key required, including request and response schemas and runnable examples in 10 languages. Those schemas help implement documented mappings rather than guess at DNS and mail payloads. That matters at the exact boundary this example leaves to the integration adapter.
Existing ownership can outweigh consolidation. A team already operating its DNS, mail, and metrics integrations can keep those systems and use the same reconciliation contract. Compare the work needed to obtain fresh, interpretable evidence, including who maintains the adapters, rather than counting dashboard features.
Won't this page us for retired domains or miss new changes?
Retirement belongs in the active inventory. Remove a publication deliberately, then stop emitting its readiness observations. Missing DNS evidence alone cannot tell you whether that happened. The sample makes retirement explicit so the operator does not have to infer a business decision from record absence.
A daily interval has a real trade-off: it leaves a detection gap between checks. Use faster checks while a customer is actively setting up a domain if that workflow needs quicker feedback, then choose a steady audit cadence appropriate to configuration that should remain stable. The example's daily schedule is a policy choice, not a delivery guarantee.
The second likely objection is that the mail service already verifies domains. Keep that signal! It answers a different question from “do the published records still match the approved intent?” Both can be valuable without either being sufficient. Agreement supplies the operational explanation, while retained metrics show when the relationship changed.
References for implementation should cover each boundary separately: DNS integration, customer-domain handling, and mail authentication. DMARC is relevant background for sending-domain policy; it does not replace the mail-service observation or certify that a particular message reached an inbox.