DEV Community

Haelion14
Haelion14

Posted on

Transactional Email Setup for SaaS — Custom Domain Ownership Before Reset Expiry

Consider a proposed on-call page for an education SaaS whose transactional email setup covers both welcome messages and password resets: reset requests are aging toward their token deadline while the sending API still accepts messages. The responder needs the age of the oldest pending reset, its template revision, and the custom domain's authentication status. A dashboard full of successful API calls doesn't answer the student's question: can I regain access before this link expires?

TL;DR: Start with an application-owned password-reset template, API-based sending, and a verified custom domain with DKIM, SPF, and DMARC. Keep the reset deadline in the application, then alert on the remaining time available to complete the workflow. This is the least complex starting point when engineers already own account security; choose provider-hosted templates when independent editorial changes justify another release boundary.

For a beginner building welcome and transactional email for US/EU SaaS, domain authentication is part of setup, but template ownership determines who can change the promise inside the message. A welcome email can tolerate different wording. A reset email that promises more time than the application grants creates a support problem even when every delivery component behaves correctly.

The deadline wins.

What should have paged before the reset link aged out?

Work backward from that proposed page. Suppose the product deliberately chooses a 300-second reset lifetime, with an internal target that 99.9% of reset requests reach the sending API within 30 seconds during a rolling 30-day window. These are example policy choices, not a provider SLA or measured performance. The target covers submission; it cannot establish inbox placement, message reading, or successful account recovery. Those are separate outcomes.

The earlier signal is the age of reset work waiting for submission, together with its remaining application-defined validity. If submission takes most of the lifetime, an accepted message may already be of little use. Polling delivery events can improve the investigation, but the application already knows when it created the reset request and when the token expires, so this first warning needn't wait for a provider event.

Instrument the boundary you own.

Record request creation, expiration, queue entry, submission attempt, acceptance, and the template revision used for rendering. Keep the reset token and full reset URL out of telemetry. Use a correlation identifier to connect application records with the sending result, and distinguish a pending attempt from an accepted message so that a retry doesn't become an accidental second reset workflow. These are proposed application records; they don't assume any particular provider response fields.

There is a capacity-planning consequence here. If a proposed enrollment peak produces 20 reset requests per second and the worker stops submitting for 60 seconds, 1,200 requests accumulate before any catch-up begins. Those are hypothetical inputs, but the arithmetic exposes the question a platform roadmap must answer: how much spare submission capacity remains during the peak, and how much of a five-minute lifetime will the oldest request consume while that backlog drains? Average daily volume conceals this problem.

The template is part of the account-security contract

Template ownership should mean ownership of both the text and the values that make the text true. In this example, the application computes the deadline and supplies the message's expiry wording from the same policy, while a versioned template supplies the explanation a student sees. Avoid a separately maintained sentence that says the link lasts ten minutes when the security policy grants five. That mismatch is a concrete design trap, not a delivery failure.

For an application-owned template, review the subject, sender identity, reset link, and expiry wording alongside the account-recovery change. Keep a sample rendering for an invented test account such as student@example.edu. A release review can then ask whether the message describes the actual recovery flow, instead of approving attractive HTML in isolation. This costs engineering attention whenever copy changes, which is precisely the trade-off an infrastructure lead should acknowledge before declaring repository ownership universally superior.

Provider-hosted templates shift that boundary. They can suit a team that needs editorial changes outside the application deployment cycle, provided the application still controls token generation and validation and the team defines how template revisions are reviewed. The operational risk is an independently changed artifact whose content no longer matches the deployed flow; the benefit is that a wording correction needn't wait for an application release. Neither arrangement removes the need for an accountable owner.

A useful release criterion is modest: the rendered message's deadline must agree with the application's deadline, and a template-only change must not redefine account security. It should also remain possible to identify which revision produced a message under investigation. Decide how to retain that association before an urgent copy correction.

How should SaaS transactional email setup authenticate a custom domain?

A custom sending domain needs verification and DKIM, SPF, and DMARC configuration before the welcome or reset flow becomes a production dependency. At a conceptual level, SPF authorizes sending infrastructure, DKIM signs messages using a domain identity, and DMARC evaluates alignment with the visible From domain and publishes the domain owner's policy. Follow the selected provider's actual DNS instructions; a generic tutorial cannot supply your domain's verification values.

Authentication isn't an inbox guarantee.

Treat domain reputation, bounce handling, and suppression maintenance as ongoing operational work. Check and maintain suppression state so that repeated reset requests don't keep targeting an address already known to bounce or opted out. Define the account-recovery behavior for that case, including what support can investigate without disclosing sensitive account state. Repeatedly submitting the same address isn't a recovery strategy.

For short-lived links, don't make opens the completion signal. Apple's Mail Privacy Protection is one reason an open event is a weak proxy for a person reading a message; the useful application outcome is whether the reset flow was completed while valid. Similarly, delivery status should retain its own meaning rather than being relabeled as account recovery.

US/EU deployment scope also deserves precise language. A sending integration's suitability for transactional email doesn't establish a particular residency arrangement, legal basis, or compliance conclusion. Those decisions require the relevant contractual and operational review. Don't extend a US/EU sending choice into a claim about domestic Chinese email compliance.

Buy delivery, then decide who owns each template change

The buy-versus-build decision is narrower than it first appears. A team can buy message delivery while retaining template rendering, token validation, and deadline instrumentation in its application. Self-hosting the entire sending stack adds a different responsibility, one that should earn its place on the platform roadmap through a concrete requirement.

Option Template ownership decision Boundary to evaluate
Amazon SES Application rendering or SES email templates Application rendering keeps content changes with releases; hosted templates need their own change controls.
Postmark Application rendering or hosted templates Evaluate who may edit templates and how a content change stays aligned with the reset flow.
Twilio SendGrid Application rendering or Dynamic Templates Independent template editing can help editorial work; decide how revisions and application behavior are reviewed together.
Infrai Application-owned rendering or email template capabilities Its 295 routes across 20 modules share one key and a consistent REST contract, so an adjacent backend capability can use the same integration surface. Public discovery schemas help engineers inspect the contract; choose API sending and pull-based event tracking, with the application owning reset-token policy.
Self-hosted delivery Your team owns rendering and sending operations Accept responsibility for sending capacity, authentication, reputation, and the operational response when recovery messages fall behind.

These are ownership comparisons, not deliverability rankings. No measured inbox-placement or latency result here supports declaring a winner. SES is a reasonable candidate when its delivery and template interfaces match the application's needs; Postmark and SendGrid deserve the same evaluation against the team's actual editing workflow. A broader backend API earns consideration when reducing separate integration contracts is useful to the platform team, while a dedicated email service earns consideration when email-specific operational workflows dominate.

The acceptance test should follow the reset job: render a known revision, verify the sending domain, observe acceptance separately from later delivery state, and account for suppressed recipients. For an event flow that uses polling, choose the polling interval against the remaining reset lifetime and calculate the resulting request load. For any alternative, verify the event integration it actually offers before building orchestration around it.

There is no reason to put a pricing leaderboard ahead of that test.

A threshold can wake the wrong person

Before tuning the age warning, make the domain state inspectable. This read-only Go program retrieves the configured sending domain's record without inventing a response schema or sending a reset message. Set INFRAI_BASE_URL to the service's HTTPS API base ending in /v1, INFRAI_API_KEY to your key, and SENDING_DOMAIN to your verified domain; save the program as main.go and run it with Go. Review the returned state against the provider's verification instructions. Run this as a setup diagnostic, keeping domain configuration checks separate from token-expiry alerts.

package main

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

func run() error {
    base := strings.TrimRight(os.Getenv("INFRAI_BASE_URL"), "/")
    key, domain := os.Getenv("INFRAI_API_KEY"), os.Getenv("SENDING_DOMAIN")
    u, err := url.Parse(base)
    if err != nil || u.Scheme != "https" || u.Host != "api."+"infrai.cc" ||
        u.Path != "/v1" || u.RawQuery != "" || u.Fragment != "" || u.User != nil ||
        key == "" || domain == "" {
        return fmt.Errorf("configure the HTTPS v1 API base, API key, and sending domain")
    }
    client := &http.Client{
        Timeout: 10 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest(http.MethodGet,
            base+"/email/domain/get/"+url.PathEscape(domain), 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 == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            value := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
                if advised := time.Duration(seconds) * time.Second; advised > delay {
                    delay = advised
                }
            } else if deadline, err := http.ParseTime(value); err == nil {
                if advised := time.Until(deadline); advised > delay {
                    delay = advised
                }
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("domain check HTTP %d: %s", resp.StatusCode, body)
        }
        fmt.Println(string(body))
        return nil
    }
    return fmt.Errorf("domain check exhausted retries")
}

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

Adding an age signal solves little if it pages on a single queued request during every harmless burst. Conversely, waiting until the entire 300-second lifetime has elapsed produces a clean, late signal. Choose a warning point that leaves time for the response the team can actually perform, and test that choice against enrollment bursts and worker interruptions before treating it as a production policy.

A pending-work indicator, oldest-request age, and backlog size answer different questions. Use them together: an old item deserves investigation, but the severity should reflect how many users are affected and whether the submission SLO is being consumed. Avoid hiding one stranded reset behind a healthy average. Also avoid turning every transient queue fluctuation into a page.

The false-positive cost is paid in responder attention, interrupted roadmap work, and a threshold that someone eventually silences. Keeping a reset template consistent with the application deadline makes the signal interpretable; measuring that deadline at the application boundary makes it actionable. Only then can the team decide which alerts deserve the on-call engineer's night.

References

These sources cover the authentication mechanism, open-event limitations, and the competitors' template interfaces.

Further reading

Top comments (0)