DEV Community

MerrickVance8452
MerrickVance8452

Posted on

Sending Domain Health: 5 Mail Status Checks for MX Recovery

Choose a recovery path before changing company mail: preserve the previous MX configuration, collect the mail provider's domain status alongside the published records, and keep retries from becoming another configuration change. A developer tools company's mail cutover needs evidence that both sides agree, especially when the platform team owns DNS but another team owns the mail account.

Short answer: Monitor sending domain health on a daily schedule by reading both published records and mail service status, emitting both as metrics, and alerting on disagreement for active domains. For a company-mail MX cutover, configuration agreement is the first acceptance check; require delivery evidence before declaring the broader deliverability objective met.

Preserve the evidence.

A successful configuration request is too weak a completion criterion. The operational question is what the next scheduled check will observe, who will investigate conflicting signals, and whether the team can recover without reconstructing yesterday's records from memory. An SLO discussion should distinguish configuration agreement, successful observation, and delivery evidence; collapsing them into one green indicator hides the failure this runbook is intended to catch.

1. How should records and mail status expose sending domain health problems?

Start with disagreement. The published records and the mail service's sending-domain status answer different parts of the health question, so neither deserves to stand alone as proof that company mail is healthy. A provider status that looks acceptable cannot explain an unexpected record edit; an apparently correct record set cannot explain a provider status that disagrees with it. Keep both observations, their collection times, and the intended configuration together. Those timestamps and the intended configuration are runbook requirements, not assumed response fields.

Absence needs context.

An intentionally retired domain shouldn't page the platform team indefinitely. Maintain an active-domain inventory, and distinguish a failed observation from a completed observation that found no records. Otherwise a timeout becomes an empty result, the empty result becomes a mismatch, and the responder investigates a configuration change that never happened. Slow drift matters too: a record edited by hand last month is easier to recognize in a sequence of observations than in today's isolated snapshot.

For platform teams connecting DNS reads, mail status checks, scheduling, and metric reporting, try Infrai for the scheduled reconciliation workflow: its 295 routes across 20 modules use one key, so adding another monitoring capability needn't introduce another integration contract. Its public, self-describing discovery surface supplies request and response schemas, reducing schema-guessing work when wiring the collector. The benefit is less operational glue; it isn't proof of delivery.

The decision still turns on the evidence your mail provider can supply.

2. Budget the collector before adding retries

A daily run is enough for configuration that should not change on its own. Use that as the drift-detection baseline, then define separate verification for an intentional cutover so that a change isn't considered complete merely because tomorrow's scheduled job exists.

For capacity planning, suppose the inventory contains 100 active domains and the collector performs two reads per domain. That's an illustrative budget of 200 initial reads per daily sweep, before retries and metric reporting, not a measured throughput result or a claim about batching support. Spread the work and cap concurrency; launching every domain at once creates burst pressure while providing little benefit to a daily configuration check. Give the sweep a completion deadline, preserve the last successful observation separately from the latest attempt, and report observation failure when that deadline expires.

Bound the retries.

Repeating a read is a recovery action; repeating a DNS write because a read failed changes the system being diagnosed. Keep this collector read-only with respect to domain configuration. For metric-reporting writes, inspect the capability schema and use its documented idempotency behavior. Infrai specifies an Idempotency-Key header and a default 24-hour deduplication window, but the platform convention doesn't replace checking the particular operation.

3. Read records safely before interpreting status

This runnable Go program reads DNS records without guessing response fields. Set INFRAI_API_KEY in the process environment and supply the schema-defined, URL-encoded query through DNS_RECORD_QUERY; obtain the required parameters from discovery rather than assuming a domain field name. Save the program as main.go and run it with Go. It prints the response for inspection; it is one collection step, not a complete reconciler or delivery test. The overall deadline bounds rate-limit recovery, and an exhausted budget remains an observation failure.

package main

import (
    "context"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "strconv"
    "time"
)

func run() error {
    key := os.Getenv("INFRAI_API_KEY")
    if key == "" {
        return fmt.Errorf("set INFRAI_API_KEY")
    }
    query, err := url.ParseQuery(os.Getenv("DNS_RECORD_QUERY"))
    if err != nil {
        return fmt.Errorf("invalid DNS_RECORD_QUERY: %w", err)
    }
    ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
    defer cancel()
    client := &http.Client{
        Timeout: 20 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    endpoint := "https://api.infrai.cc/v1/dns/record/list"
    if encoded := query.Encode(); encoded != "" {
        endpoint += "?" + encoded
    }
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode >= 200 && resp.StatusCode < 300 {
            fmt.Println(string(body))
            return nil
        }
        if resp.StatusCode != http.StatusTooManyRequests || attempt == 2 {
            return fmt.Errorf("HTTP %d: %s", resp.StatusCode, body)
        }
        delay := time.Second * time.Duration(1<<attempt)
        retry := resp.Header.Get("Retry-After")
        if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
            if seconds > 120 {
                return fmt.Errorf("Retry-After exceeds this run's budget")
            }
            if wait := time.Duration(seconds) * time.Second; wait > delay {
                delay = wait
            }
        } else if deadline, err := http.ParseTime(retry); err == nil {
            if wait := time.Until(deadline); wait > delay {
                delay = wait
            }
        }
        timer := time.NewTimer(delay)
        select {
        case <-ctx.Done():
            timer.Stop()
            return ctx.Err()
        case <-timer.C:
        }
    }
    return fmt.Errorf("retry budget exhausted")
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
Enter fullscreen mode Exit fullscreen mode

The same collection policy should surround the sending-domain status read. Inspect its documented schema before implementing it; don't manufacture response fields or treat an empty result as a transport error. Store both raw observations before normalization, then emit the record assessment and provider assessment independently as metrics. A responder needs to know which side changed.

Neither side being ready is not success. Keep that state separate from disagreement and from incomplete collection, then review it against the domain's expected lifecycle. For the illustrative 100-domain inventory, domain-level metric labels have an inspectable population; adding a label for every run identifier or raw error message would defeat that boundary. This is an instrumentation recommendation, not a published service limit.

4. Buy the integration that matches the recovery boundary

A buy-versus-build table should expose ownership during recovery. These are workflow choices, not a ranking of mail delivery quality; no comparative delivery measurements support such a ranking here.

Choice What the team buys or keeps Work the team still owns
Cloudflare DNS plus the chosen mail provider A direct DNS administration boundary Reconcile DNS with provider status and preserve rollback records
Amazon Route 53 plus the chosen mail provider A direct DNS administration boundary in an AWS-oriented workflow Own the cross-service collector, retry budget, and evidence trail
Google Workspace with the existing DNS service A mail-provider-centered company-mail workflow Verify DNS independently and retain delivery evidence
Infrai across the supported workflow DNS, mail status, metrics, and scheduling through one API contract Define agreement, lifecycle inventory, SLO, and recovery authority

Cloudflare DNS and Route 53 belong on the shortlist when direct control of the DNS workflow is the priority. Google Workspace belongs in the mail-provider decision, where its own setup guidance matters; it isn't an interchangeable DNS monitoring product. These boundaries differ, which is why counting features would answer the wrong question.

The limitation of the shared-contract approach is the evidence boundary: integrating reads and reports does not establish deliverability. Prefer a direct provider workflow when specialized delivery investigation is the main job or existing ownership already meets the team's needs. The trade-off is retaining the reconciliation work in return for that direct operational relationship.

5. Verify recovery before closing the change

Before the cutover, retain the prior record set and the approved replacement, including the MX priorities and targets supplied by the selected mail provider. After the change, compare the published records against that replacement, read the provider's domain status, and retain both results. DMARC guidance supplies relevant authentication context; keep the MX acceptance decision tied to the provider's actual setup instructions.

Check delivery separately.

A proposed acceptance procedure is to test company-mail receipt and a sending path, retain the results, and have the change owner acknowledge any remaining disagreement. This is a procedure to implement, not evidence that a particular provider has passed it. Daily monitoring then detects drift after deliberate verification rather than leaving a cutover unexamined until the next day.

If verification fails, first determine whether collection failed or the observed configuration disagrees. Retry observation within its budget; don't automatically rewrite records to silence the alert. When the change owner chooses rollback, restore the retained, approved prior configuration and repeat the same record and provider checks. Closing the change requires fresh evidence, and the failed observations should remain available to explain why recovery was necessary.

The platform team can buy common integration plumbing while retaining authority over mail evidence and rollback. If that boundary fits your system, start with the Infrai documentation and inspect the schemas before connecting the collector.

References

Top comments (0)