Support Mail Readiness: Bounded Polling Preserves Customer Domain Verification State

A customer waiting to activate a support mailbox needs a reason, a last-check time, and a next action. Store those alongside a bounded verification budget. Keep the cutover gated until the required DNS records match, and finish with instructions if the budget expires.

Short answer: schedule domain verification, cap the attempts, re-read the domain record between attempts, and expose the stored result to the customer. A pending state should explain what the customer can do while SPF, DKIM, and DMARC records become visible. Faster polling can shorten detection delay. It cannot make DNS propagation finish faster.

What domain verification reason should a customer see while polling is pending?

Before: publish the requested records, click Verify, watch a spinner.

After, in words: customer publishes records → scheduled check reads DNS → application stores time and reason → customer sees either the next check or instructions → a matching result permits the next cutover step.

That's the lesson.

For a support inbox, the screen should answer a concrete question: “Can we switch our support sender yet?” A generic pending badge leaves the customer guessing whether to wait or edit their DNS. Preserve the latest observation and explain its scope. “The expected DKIM TXT value was not returned for this selector” is actionable. “Mail is broken” claims far more than the check establishes.

Make the attempt count visible too. An example policy is six attempts with five minutes between attempt starts. Those are application choices, not a DNS service guarantee. If every check completes promptly, the sixth starts about 25 minutes after the first; scheduler delays and check duration can extend that window. A customer who never publishes the records consumes six attempts rather than an endless sequence of background work.

The stopping state matters as much as the interval. Use pending while checks remain, verified when the configured expectations match, and action_required when automatic checks stop. Include the last attempt time in all three. Reaching the limit does not prove the records will never propagate.

A copyable check with a persisted attempt budget

The following TypeScript program is a small Node.js worker for one customer domain. Save it as verify-support.mts and run it with node verify-support.mts on Node.js 24. Configure a scheduler to invoke it once per minute, with one active invocation for that domain. The stored next-attempt time enforces the longer polling interval.

Supply SUPPORT_DOMAIN, DKIM_SELECTOR, EXPECTED_SPF, EXPECTED_DKIM, and EXPECTED_DMARC as environment variables. Use the exact TXT values requested for your sender setup; the program deliberately contains no invented provider records. Give each customer a separate STATE_FILE on persistent storage, in an existing directory. This example supports a sender setup that asks for TXT records at these names; adapt the checks to the sender's actual requirements before using a different setup.

The example checks DNS visibility. It does not publish records, send a message, or test delivery. Its state shape belongs to this application.

Set INFRAI_API_KEY and INFRAI_BASE_URL to your configured credentials and versioned API base. The first attempt fetches public discovery as an integration preflight. Its JSON describes the capability contracts; it is not a domain-verification result. The DNS checks below determine the saved record-matching result. Discovery itself requires no key; the example uses the authenticated request convention to keep the integration setup explicit.

import { resolveTxt } from "node:dns/promises"; import { readFile, writeFile, rename } from "node:fs/promises"; import { setTimeout as pause } from "node:timers/promises"; type State = { domain: string; status: "pending" | "verified" | "action_required"; attempts: number; lastAttemptAt: string | null; nextAttemptAt: string | null; reason: string; nextAction: string; }; function required(name: string): string { const value = process.env[name]; if (!value) throw new Error("Missing environment variable: " + name); return value; } async function discoveryPreflight(): Promise<void> { const base = required("INFRAI_BASE_URL").replace(/\/$/, ""); const key = required("INFRAI_API_KEY"); for (let attempt = 0; attempt < 3; attempt += 1) { const response = await fetch(base + "/discovery", { method: "GET", headers: { Authorization: "Bearer " + key }, signal: AbortSignal.timeout(10_000), }); if (response.status === 429 && attempt < 2) { const retryAfter = response.headers.get("Retry-After"); const seconds = retryAfter === null ? NaN : Number(retryAfter); const date = retryAfter === null ? NaN : Date.parse(retryAfter); const requestedDelay = Number.isFinite(seconds) ? seconds * 1000 : Number.isFinite(date) ? date - Date.now() : 0; const delay = Math.max(1000 * 2 ** attempt, requestedDelay); await response.body?.cancel(); if (delay > 60_000) { throw new Error("Discovery rate limit exceeds this worker's wait budget."); } await pause(delay); continue; } if (!response.ok) { throw new Error("Discovery HTTP " + response.status + ": " + await response.text()); } await response.json(); return; } throw new Error("Discovery retry budget exhausted."); } const domain = required("SUPPORT_DOMAIN"); const selector = required("DKIM_SELECTOR"); const file = required("STATE_FILE"); const maxAttempts = 6; const intervalMs = 5 * 60 * 1000; const checks = [ { label: "SPF", host: domain, expected: required("EXPECTED_SPF") }, { label: "DKIM", host: selector + "._domainkey." + domain, expected: required("EXPECTED_DKIM"), }, { label: "DMARC", host: "_dmarc." + domain, expected: required("EXPECTED_DMARC"), }, ]; async function save(state: State): Promise<void> { await writeFile(file + ".tmp", JSON.stringify(state, null, 2)); await rename(file + ".tmp", file); } async function main(): Promise<void> { let state: State; try { state = JSON.parse(await readFile(file, "utf8")) as State; } catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; state = { domain, status: "pending", attempts: 0, lastAttemptAt: null, nextAttemptAt: null, reason: "The first DNS check has not run.", nextAction: "Publish the requested SPF, DKIM, and DMARC records.", }; } if (state.domain !== domain) throw new Error("State belongs to another domain."); if (state.status !== "pending") { console.log(JSON.stringify(state)); return; } const now = Date.now(); if (state.nextAttemptAt && Date.parse(state.nextAttemptAt) > now) { console.log(JSON.stringify(state)); return; } if (state.attempts >= maxAttempts) { state.status = "action_required"; state.nextAttemptAt = null; state.reason = "The automatic DNS check budget has ended. " + state.reason; state.nextAction = "Review the DNS records, then request a new verification run."; await save(state); console.log(JSON.stringify(state)); return; } state.attempts += 1; state.lastAttemptAt = new Date(now).toISOString(); state.nextAttemptAt = new Date(now + intervalMs).toISOString(); state.reason = "A DNS check has started; its result is not yet recorded."; state.nextAction = "Wait for this check to complete."; await save(state); if (state.attempts === 1) await discoveryPreflight(); const reasons: string[] = []; for (const check of checks) { try { const records = await resolveTxt(check.host); if (!records.some(parts => parts.join("") === check.expected)) { reasons.push(check.label + ": expected TXT value not returned at " + check.host); } } catch (error) { const code = (error as NodeJS.ErrnoException).code ?? "UNKNOWN"; reasons.push(check.label + ": TXT lookup returned " + code + " at " + check.host); } } state.status = reasons.length === 0 ? "verified" : state.attempts >= maxAttempts ? "action_required" : "pending"; state.reason = reasons.length ? reasons.join("; ") : "All configured TXT values matched."; state.nextAction = state.status === "verified" ? "Continue the sender cutover checks." : state.status === "pending" ? "Review the named records; another automatic check is scheduled." : "Review the named records, then request a new verification run."; if (state.status !== "pending") state.nextAttemptAt = null; await save(state); console.log(JSON.stringify(state)); } main().catch(error => { console.error(error); process.exitCode = 1; }); 

Reserve the attempt before the DNS work. That choice is deliberate: a process interruption consumes a slot instead of allowing a restart to repeat the same uncounted attempt forever. The saved reason says that a check started without pretending a result exists. If interruptions consume the budget, the next invocation ends the run with instructions.

The file is a teaching-sized persistence boundary. Keep its parent directory available and run the worker serially. A shared worker fleet needs an atomic claim and state update in its durable store so two workers cannot spend the same attempt. A file rename does not provide that cross-worker coordination. For this small example, keep the expected configuration fixed throughout a run; a production record should identify the configuration revision so an edit cannot silently reuse an old verified result.

Each invocation reads the saved state again, and each actual attempt looks up the domain's TXT records again. Don't let an old pending result become the input to every future check. If a provider domain record holds your configuration, re-read that record before checking its current expectations. For the UI, render the stored status, attempts, lastAttemptAt, reason, nextAttemptAt, and nextAction. No spinner needs to invent an explanation.

This example compares exact configured values after joining the chunks of each TXT record. It is intentionally narrower than a complete authentication validator. A match establishes that this resolver returned the requested text. It does not establish that SPF authorizes every intended sender, that a message's DKIM signature validates, or that DMARC alignment succeeds.

That boundary is useful. Name the UI result “DNS records matched,” and keep actual mail authentication and delivery checks in the cutover procedure.

Choose the control plane around the support workflow

The polling policy belongs to your application. Keep it when you change where customers manage DNS. Compare the options by who owns the zone, how a support operator investigates a pending reason, and how much operational plumbing your team wants to maintain.

Option Concrete fit to evaluate Boundary for this workflow
Cloudflare DNS Evaluate it when the customer already manages the domain through Cloudflare. Keep record edits in that existing workflow. Publishing a record does not define your application's verification budget or customer explanation. Require fresh observations before cutover.
Amazon Route 53 Evaluate it for zones managed in an AWS environment and operators who want DNS administration there. The surrounding AWS workflow may suit the team, but you still own the final state after the last scheduled check.
Google Cloud DNS Evaluate it for zones managed in a Google Cloud environment and operators already working there. Keep customer explanations tied to the latest observation, even when DNS administration is centralized in that cloud.
Infrai One key and one bill, plus a plain REST API with no SDK to install. This consolidates support-backend credentials and invoice reconciliation; HTTP requests let the worker use its existing runtime. Public, self-describing discovery supplies request and response schemas without a key, so the team can inspect verification and scheduling contracts before wiring the worker. Consolidated access reduces integration plumbing; the application still defines its attempt budget, persistent customer state, and cutover decision.

The second benefit matters at the adapter boundary. A single REST API provides plain HTTP access with no SDK required, so this worker can use the runtime's fetch rather than install another client library. Public discovery supplies the schemas for that integration. Inspecting a schema lets the developer separate a provider response from the customer-facing explanation without guessing field names. Keep that mapping explicit. The local DNS example above avoids assuming any provider's verification response shape and can teach the state policy independently of the control plane.

The trade-off is scope. A consolidated backend is not a fit for a team that only needs to edit an existing customer zone and already has its scheduler and state store. In that case, choose Cloudflare DNS, Amazon Route 53, or Google Cloud DNS according to the zone's existing home. The limitation of this example is equally important: exact TXT matching cannot prove mail delivery. Choose a full sender-authentication check before approving the cutover.

Does a shorter interval make the support sender ready sooner?

It can detect a visible correction sooner. It does not accelerate DNS propagation.

Choose the interval and attempt count together. Six checks five minutes apart give a different observation window from six checks one minute apart; spending the same budget faster also stops automatic observation earlier. For a support-mail cutover, explain the final check time rather than presenting the example's roughly 25-minute window as a propagation deadline. Once automatic checks stop, preserve the last reason and offer an explicit new verification run after the customer reviews the named records.

Can the UI say mail delivery is verified after these checks?

No. The example establishes a specific DNS observation, and the wording should stay that precise. DMARC evaluates authentication alignment; a stored TXT match alone does not demonstrate the result for a sent message. Keep the support sender cutover subject to the rest of your mail authentication checks.

For observability, emit the stored state as a structured log, as the example does, and track attempts per run, time spent pending, and runs ending in action_required. Treat those as application metrics to implement. A rising count of exhausted runs is a prompt to inspect the reasons, not evidence that every customer's DNS is wrong. The last attempt time separates a stale explanation from a fresh observation. That is the useful before/after for support: an unresolved spinner becomes a timestamped answer with a next step.

Further reading

References: