Send transactional emails with the API
Use the REST API to send transactional email from any language. If your language has a server SDK, start there: the SDKs call this API and retry with idempotency keys for you.
Before you start
- A project secret API key: create one with the
transactional_email:writescope. Keep it on your server. - Your host: send to
https://us.posthog.comorhttps://eu.posthog.com, the host where you log in to PostHog. Don't use an ingestion host likeus.i.posthog.com. If you self-host PostHog, use the URL of your instance. - A verified domain: until you verify your domain, emails go only to your team, from the test sender.
The path has no project ID. PostHog sends from the project that the key belongs to.
Send your first email
Send the subject and the HTML from your code. template_key names the email, such as password-reset, so PostHog can group its sends and metrics. Use the same key every time you send this email.
to: one recipient for each request.distinct_id: optional. The distinct ID that you pass toidentify(). PostHog records the email's engagement events on this person.from: optional. An address on a verified domain. If you leave it out, PostHog uses the project's default sender.Idempotency-Key: optional, but recommended. A retry with the same key never sends the email twice.
A successful request returns 202 Accepted:
A 202 means that PostHog queued the email, not that it was delivered. Keep the message_id to check the status. replayed is true when an earlier request with the same Idempotency-Key already queued the email. PostHog then sends nothing new.
Send a PostHog template
To let your team edit the copy without a deploy, keep the email in PostHog as a transactional template. Send template_id and message_data in place of template_key, subject, and the body:
message_data fills the template's {{ variables.* }} placeholders, such as {{ variables.reset_link }}. The template can't read person properties, so pass all the data that the email needs.
Check the status
Read the status with the message_id from the send. The key needs the transactional_email:read or transactional_email:write scope (existing keys with hog_flow:read also work; use transactional_email:read for new read-only keys).
If you lost the response of a send, read the status by its idempotency key instead:
A found email returns 200:
A new send can take a few seconds to get its first status, so a 404 right after a send means that you must retry after a short wait. See statuses and reasons for what each value means.
Next steps
| To do this | Read |
|---|---|
| See every field, response, and operational error code | Transactional email API, email logs API, and retries and errors |
| Build a production integration | Send emails from code |
| Attach files and inline images | Attachments |
| Protect login links and turn off tracking | Sensitive data |
| Handle errors, retries, and idempotency keys | Retries and errors |
| Check rate limits and quotas | Limits, quotas, and sending tiers |





