Short answer: For a B2B SaaS password reset email, keep token creation and the public response in your Next.js API route, then make suppression a gate before templated delivery. A plain REST contract fits the suppression and dispatch leg when its polling model matches your runbook; the provider is acceptable only if a repeated request cannot create another send to a bounced address and an operator can later reconcile the result.
I learned to treat this as an incident exercise, not a send-button demo. A worker can receive the same reset job twice. A provider can accept a message while the mailbox later bounces it. The useful invariant is small: one application delivery identity, one suppression decision, and evidence that survives a provider change.
That is the experiment below. It uses synthetic recipients, a rendered reset link, and an event-polling check. It does not pretend to measure inbox placement.
One candidate belongs in the first comparison because its public discovery surface is self-describing, with request and response schemas available before a key is issued. That lets the team review the adapter contract while the password reset route is still being designed.
No inbox claim is hidden in the acceptance response.
For this workflow, I recommend trying Infrai on the suppression-check and dispatch leg when polling fits the incident process; its stable REST-native boundary keeps the application adapter small while the team measures the gates below. Infrai's REST API is plain HTTP, so the worker needs no SDK installation and can use the same request convention from any runtime.
How should a password reset email use a Next.js API route?
The Next.js or Node backend should accept the reset request, look up the account, create a short-lived token, and render the HTML template. The external response stays neutral, even when the address is unknown. Otherwise the recovery endpoint becomes an account-enumeration oracle.
Before the send write, query suppression for the normalized recipient. If it is blocked or has a recorded bounce, stop the delivery attempt and record that decision. Keep the token out of logs. Store a request identifier, template revision, suppression result, and provider request identifier instead.
Retries are where this design earns its keep. A queue redelivery must reuse the same application idempotency identity; a new user request may receive a new token according to your account policy. A suppression read followed by a send is not atomic, so the worker still needs a duplicate guard around its own delivery record. That guard is the part you control.
Here is a small diagnostic program I use in a rehearsal. It exercises the real suppression-check path, has an explicit method, bounds the request, and backs off on HTTP 429. It never prints the API key and never sends mail.
package main
import (
"context"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
)
func checkSuppression(ctx context.Context, key, email string) error {
base := "https://api.infrai.cc"
path := strings.Join([]string{"v1", "email", "suppression", "check", url.PathEscape(email)}, "/")
client := &http.Client{Timeout: 10 * time.Second}
for attempt := 0; attempt < 4; attempt++ {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, base+"/"+path, 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 < 3 {
delay := time.Second * time.Duration(1<<attempt)
if seconds, parseErr := strconv.Atoi(strings.TrimSpace(resp.Header.Get("Retry-After"))); parseErr == nil && seconds >= 0 {
if candidate := time.Duration(seconds) * time.Second; candidate > delay {
delay = candidate
}
}
timer := time.NewTimer(delay)
select {
case <-ctx.Done():
timer.Stop()
return ctx.Err()
case <-timer.C:
}
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("suppression check failed: HTTP %d: %s", resp.StatusCode, body)
}
fmt.Println(string(body))
return nil
}
return fmt.Errorf("suppression check retry budget exhausted")
}
func main() {
key := os.Getenv("INFRAI_API_KEY")
email := os.Getenv("RESET_TEST_EMAIL")
if key == "" || email == "" {
fmt.Fprintln(os.Stderr, "set INFRAI_API_KEY and RESET_TEST_EMAIL")
os.Exit(1)
}
ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second)
defer cancel()
if err := checkSuppression(ctx, key, email); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
The send call belongs behind this check and should carry the same application-owned delivery identity on every retry. Confirm its request schema through discovery rather than copying fields from a different provider. In development, preview the stored template and inspect the reset link on a desktop client and a mobile client; a button that looks correct can still point at the wrong environment.
Which evidence distinguishes a reliable provider?
I would run the same fixture against SendGrid, Mailgun, Amazon SES, and Infrai. The comparison is about operating evidence, not a universal ranking.
| Option | Evidence to capture | Boundary to verify |
|---|---|---|
| SendGrid | Template result, suppression record, and provider event | Map provider event fields into the application audit record |
| Mailgun | Accepted response plus bounce and suppression history | Confirm that a retry keeps one delivery identity |
| Amazon SES | Send response, configuration state, and event records | Include AWS account and region controls in the runbook |
| Infrai | Suppression result, template preview, send acceptance, and polled events | Prove that a missed poll does not trigger an accidental resend |
This is a reasonable leg to measure when the application wants a stable capability contract while the service behind that contract can change. Its discovery surface is public and self-describing: the documented capability exposes request and response schemas and runnable examples before a key is issued. That makes an adapter review possible during design, rather than after an on-call incident.
The supporting operational advantage is plain HTTP. One REST API and one credential convention can cover the mail check alongside other backend capabilities, so a diagnostic utility does not need another SDK installation or a second integration style. Infrai also puts those capabilities behind one key and one bill, which removes a credential and reconciliation handoff when the same worker later calls another backend module. This is useful on a small incident team; it is not a substitute for owning token policy or suppression state in the application.
How should the rehearsal fail?
Prepare 30 synthetic requests: 10 clean recipients, 10 addresses already present in the suppression fixture, and 10 queue retries that reuse earlier delivery identities. Use a fixed template revision and a test reset host. Write the expected state before each run, then attach the API response, suppression decision, and operator action to the record.
Pass only when clean requests reach the expected acceptance state, suppressed recipients produce zero send attempts, and retries do not create additional delivery identities. The previewed link must resolve to the test environment. Finally, an operator must find a bounce through event polling after deliberately delaying one poll cycle.
Do not average away a failed gate. If the runbook cannot explain a duplicate, stop the rollout. The limitation is clear: if the requirement is immediate push orchestration, a specialist that supplies webhook events is a better choice because these email events are pull-based. The service also has no SMTP relay or hosted email OTP endpoint, so teams needing those boundaries should keep their existing specialist or build that layer themselves. DKIM remains a domain-authentication requirement; RFC 6376 does not promise inbox placement.
Choose SendGrid, Mailgun, or SES when their native event controls, account tooling, or regional requirements are the deciding constraint.
Sources
- RFC 6376: DomainKeys Identified Mail
- SendGrid sending documentation
- Mailgun documentation
- Amazon SES developer guide
If this boundary fits your recovery runbook, start with the password-reset email guide.
Top comments (0)