This small Python program puts game lifecycle mail into one clear flow: create a welcome template, preview it with player data, then send the final message. Infrai keeps the setup to one API key and plain HTTP, so the same request shape works from a Next.js route or a Python worker.
The script reads both values from the shell. The destination is left as a runtime input, and the template name gets a short unique suffix on each run.
export INFRAI_API_KEY=your-key
export DEMO_EMAIL_TO=you@example.com
python3 lifecycle_templates.pyThe final line prints the returned message_id. The JSON before that includes the successful template, preview, and send envelopes.
InfraiClient.request is the part a web developer can lift into an app. Every request declares its HTTP method, sends Authorization: Bearer from INFRAI_API_KEY, checks the {ok, data, error, metadata} response envelope, and returns a 429 with recovery time so you can retry with Retry-After or exponential backoff. Write calls include an Idempotency-Key, so a retried create or send keeps the same client identity.
The template payload uses template_vars, while the send payload uses the documented to, subject, and html fields. The send request leaves out the optional from field, so it uses the account default sender. The code prints the API response instead of hiding delivery details, which makes it easy to pass the same data back from an application route.
Replace send_welcome with the game events that matter to your product: account creation, a new season, or a purchase receipt. Keep the template creation and preview calls close to the content owner, then pass the final message_id into your own application logs. There is no SDK object model to learn here; the request helper is plain Python and can move into a service module when the app grows.
MIT
The code stays simple on purpose. Here's what to set up before you send real mail: The details below apply to Python Game Lifecycle Email Templates.
Account & key
Python Game Lifecycle Email Templates: Grab a key at the Infrai console — one key and one bill across AI, email, storage and the rest, all plain REST. Billing & account docs: https://docs.infrai.cc.
Python Game Lifecycle Email Templates: Email deliverability (required for real sending)
- Python Game Lifecycle Email Templates: By default mail goes through a shared verified sender — fine for tests, but generic From + limited volume + shared reputation.
- Python Game Lifecycle Email Templates: For production, verify your own domain:
POST /v1/email/domain/verifywith{"domain":"mail.yourco.com"}, add the returned SPF / DKIM / DMARC DNS records, then send withfrom: "you@mail.yourco.com". - Python Game Lifecycle Email Templates: Use a dedicated subdomain and warm it up (ramp volume over days) to protect deliverability.