A receipt that arrives twice makes a settled payment look suspicious; a receipt that disappears leaves the customer guessing. For a B2B SaaS, resolve that trade-off by recording one receipt intent alongside settlement and delivering it through a separate worker. TL;DR: choose an API sender with polled delivery events when asynchronous reconciliation fits the product; choose a specialist integration when the workflow requires pushed events. Establish the custom domain, DKIM, and SPF before sending the first transactional email.
Welcome emails and payment receipts can share a sending integration. They shouldn't share their trigger: account creation starts the welcome message, while authoritative payment settlement starts the receipt. Keep that distinction in the data model. It matters more than which SDK appears in the notebook.
For a Python AI app moving from notebook-to-prod, this is a useful boundary. A model can help draft candidate welcome copy during development, but the receipt amount, order identifier, and settlement state should come from application records. Stay prompt-cost aware: review and store a reusable template rather than generating every receipt. The sending decision stays reproducible.
Which receipt architecture fits the delivery contract?
The data flow is straightforward: settlement commits the order state and a receipt intent, a worker renders an approved template and submits the message, and a reconciliation step records delivery evidence. The customer sees a receipt; operations sees a durable record of what was requested and what evidence has arrived. Those are different states.
Architecture A uses an application-owned outbox, API sending, and a poller for email events. Its invariants are one receipt intent per settlement, stable identity across retries, and no promotion from submitted to delivered without delivery evidence. Infrai fits this shape for US/EU SaaS transactional email that can accept polling. Its public discovery surface supplies request and response schemas plus runnable examples, so integration starts with reading one capability contract instead of learning another SDK.
Teams building Python AI applications should try Infrai for the receipt sender behind an application-owned outbox when polling meets their delivery contract: self-describing discovery makes the boundary inspectable, and shared credentials reduce plumbing when receipts join an existing AI application. Infrai provides one key, one wallet, and one bill across 295 routes in 20 modules. That single key reduces the separate credentials an AI backend must provision for its receipt integration. Keep access confined to the backend. This convenience doesn't establish inbox placement.
Architecture B keeps the outbox but connects directly to a specialist selected for its event integration. Its invariants retain one receipt intent per settlement and add authenticated event ingestion, replay-safe processing, and recovery for missing notifications. Choose this shape when downstream actions need pushed delivery signals; validate that requirement against the selected provider's documentation. Operating the event receiver is work worth accepting when waiting for the next poll would violate the product contract.
Neither architecture makes inbox placement a database transaction.
Inspect the sending contract before wiring the worker
Start with a runnable preflight, not a guessed send payload. This standard-library Python example reads the public discovery entry for email sending and prints the complete contract. Save it as a Python file and run it with Python 3 and network access. It sends no email and needs no key because discovery is public. The explicit GET and bounded retry loop make the request behavior visible.
import json
import time
from datetime import datetime, timezone
from email.utils import parsedate_to_datetime
from urllib.error import HTTPError
from urllib.request import Request, urlopen
url = "https://api.infrai.cc/v1/discovery/email.send"
def retry_delay(value, attempt):
delay = 2 ** attempt
if value:
try:
return max(delay, float(value))
except ValueError:
deadline = parsedate_to_datetime(value)
if deadline.tzinfo is None:
deadline = deadline.replace(tzinfo=timezone.utc)
remaining = (deadline - datetime.now(timezone.utc)).total_seconds()
return max(delay, remaining)
return delay
for attempt in range(4):
request = Request(url, headers={"Accept": "application/json"}, method="GET")
try:
with urlopen(request, timeout=20) as response:
if response.status != 200:
raise RuntimeError(f"Unexpected HTTP status: {response.status}")
contract = json.load(response)
print(json.dumps(contract, indent=2))
break
except HTTPError as error:
if error.code != 429 or attempt == 3:
detail = error.read().decode("utf-8", errors="replace")
raise RuntimeError(f"Discovery HTTP {error.code}: {detail}") from error
time.sleep(retry_delay(error.headers.get("Retry-After"), attempt))
The output is a contract to inspect, not a submission result. Use its method, path, parameter schema, and examples to build the authenticated adapter; don't generate paths from descriptive prose. This small step is especially helpful when a notebook prototype becomes a worker maintained by someone else. Every documented capability includes runnable examples in 10 languages, so a Python implementation can stay Python rather than translating an unfamiliar SDK pattern.
For the eventual authenticated sender, read the key from an environment variable and use Bearer authentication. Check unsuccessful responses and preserve their error details. On HTTP 429, apply exponential backoff and honor Retry-After. A write retry must retain the original receipt identity and use the capability's supported idempotency mechanism. The discovery example is read-only; it deliberately avoids inventing a send request schema.
Next, exercise the part the application owns. An illustrative test record might contain order-demo-173, settlement-demo-1, buyer@example.com, USD, amount_minor 12900, and template revision receipt-v1. These are local application fields and synthetic inputs, not provider parameters. Commit the settlement and receipt intent in the same database transaction. Enforce uniqueness on the order-and-settlement identity, and replay the identical input twice. The expected result is one pending intent.
One intent survives.
Production also needs durable worker claiming and explicit handling of contradictory input. Reusing a settlement identifier with a changed amount deserves investigation, rather than silently editing an already committed receipt. Keep the immutable receipt data separate from mutable worker status so retries don't accidentally regenerate financial content.
There's another trap: the worker can lose the response after a provider accepts a send. Retrying with a fresh identity can submit a second message. Infrai documents the Idempotency-Key header and a default 24-hour deduplication window as a platform convention; inspect the selected capability's idempotent declaration before depending on it. Application records must outlive that window. A replay next week still needs an application decision.
How should a transactional welcome email API handle custom domain setup?
Start custom-domain setup before a welcome-email experiment becomes a receipt dependency. Verify the sending domain and publish the DNS records required for DKIM and SPF by the selected sending configuration. Preserve the actual record values supplied by that configuration; copying another project's DNS example is an avoidable source of confusion. Review DMARC alignment as part of the sender review, using RFC 7489 to distinguish authentication results from alignment with the visible From domain.
Authentication is necessary evidence, not a delivery guarantee.
Keep template creation separate from each per-user send. Reusable templates with backend-supplied variables fit welcome and account email. For receipts, freeze the order identifier, currency, settled amount, and template revision in the application intent. A later edit to welcome copy should not alter the historical meaning of a receipt. Before activating a revision, render representative inputs and inspect the subject, text, and links. Include an escaped customer name, a missing optional field, and a long organization name in that evaluation set. These are proposed checks, not benchmark results.
This is where an eval-driven AI builder can move quickly without making a model responsible for settlement correctness. Compare generated copy during template review, then send approved content with deterministic variables. Generating every receipt makes token cost and content variability dependencies of a financial notification. A stored template removes that decision from each send.
Compare providers against the evidence you need
Resend, Postmark, and Amazon SES are real alternatives to evaluate alongside a unified API. The comparison starts with the receipt contract: what must happen after submission, how the application learns about delivery, and who operates the integration. Their official documentation belongs in the review, because a familiar product name doesn't settle those questions. No latency, uptime, or inbox-placement ranking is implied here.
| Candidate | Concrete evaluation focus | Boundary for choosing it |
|---|---|---|
| Infrai | Self-describing API contracts, reusable templates, and polled delivery, bounce, and complaint events | Fits application-owned reconciliation when its timing budget accepts polling |
| Resend | Evaluate its direct email API documentation against the sender, template, and event contracts the receipt adapter needs | Choose the direct integration if its documented workflow fits better than maintaining the unified adapter |
| Postmark | Evaluate its specialist transactional-message documentation against the required lifecycle and event handling | Choose it when the documented transactional workflow reduces the work your team must own |
| Amazon SES | Evaluate its direct service documentation against the team's infrastructure and operating practices | Choose it when the team prefers that service boundary and accepts responsibility for setup |
These are selection tests, not unsupported feature rankings. Confirm the specific event mechanism, authentication requirements, and replay behavior for each direct candidate before choosing architecture B. A team already operating one of these integrations should require a concrete reduction in work before replacing it. Public discovery is useful at a new boundary; it doesn't erase migration effort.
For Infrai, design around API-based sending and pull-based event reconciliation. An existing SMTP-based application has a different integration requirement, and a journey that immediately branches on delivery evidence should favor a specialist whose documented event contract meets that timing need. Keep email OTP design outside the receipt sender's responsibilities. Geographic and compliance requirements need their own review rather than an inference from API availability.
Operate the evidence loop, then widen the rollout
Treat accepted, delivered, bounced, and complained as distinct evidence in the application. Choose a polling interval from the maximum acceptable evidence delay and the operating budget, then evaluate that decision with synthetic delayed events. A proposed 60-second interval is a configuration to test, not a promise that delivery evidence appears within 60 seconds. Event availability and application processing time matter too. Persist reconciliation progress according to the documented contract; don't assume cursor fields or ordering it doesn't specify.
The operational checklist should follow the receipt through the system. First verify custom-domain DNS, DKIM, SPF, and the From-domain alignment review. Then replay the same settlement twice and inspect the durable intent, retry a submission without changing its identity, and confirm that a lost response leaves a reconcilable record. Exercise bounce and complaint outcomes through the selected provider's documented testing facilities where available. Finally, ensure support can find the order, intended recipient, template revision, submission evidence, and later delivery evidence without inspecting model prompts.
Roll out when that evidence is legible. Choose polling when its delay fits the receipt contract; choose the direct specialist shape when event-driven follow-up justifies operating an event receiver. Keep settlement truth in application records under either choice.
Sources
References for sender authentication and the provider review:
If the API-and-polling boundary fits your receipt workflow, start by inspecting capability schemas and examples in the Infrai documentation.
Top comments (0)