> AI agents: this is one page from PostHog's docs. Full index of Markdown docs for LLMs: https://posthog.com/llms.txt # Send transactional emails with the API Canonical URL: https://posthog.com/docs/workflows/installation/api > **Cloud region:** This page uses US Cloud hosts. For an EU Cloud project, use `https://eu.i.posthog.com` instead of `https://us.i.posthog.com` (ingestion host). ## On this page - [Before you start](#before-you-start) - [Send your first email](#send-your-first-email) - [Send a PostHog template](#send-a-posthog-template) - [Check the status](#check-the-status) - [Next steps](#next-steps) Use the REST API to send transactional email from any language. If your language has a [server SDK](https://posthog.com/docs/workflows/reference.md#server-sdks), start there: the SDKs call this API and retry with idempotency keys for you. ## Before you start - **A project secret API key:** [create one](https://posthog.com/docs/workflows/transactional/send-from-code.md#create-an-api-key) with the `transactional_email:write` scope. Keep it on your server. - **Your host:** send to `https://us.posthog.com` or `https://eu.posthog.com`, the host where you log in to PostHog. Don't use an ingestion host like `us.i.posthog.com`. If you self-host PostHog, use the URL of your instance. - **A verified domain:** until you [verify your domain](https://posthog.com/docs/workflows/domain.md), emails go only to your team, from the [test sender](https://posthog.com/docs/workflows/email/test-sender.md). 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. ```bash curl -X POST "https://us.posthog.com/api/messaging/send/email/" \ -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: password-reset-8f14e45f" \ -d '{ "template_key": "password-reset", "to": "jane@example.com", "distinct_id": "user_123", "subject": "Reset your password", "html": "

Hi Jane,

Reset your password.

", "from": "Hedgebox " }' ``` - **`to`:** one recipient for each request. - **`distinct_id`:** optional. The distinct ID that you pass to `identify()`. PostHog records the email's [engagement events](https://posthog.com/docs/workflows/email/engagement-events.md) 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`: ```json { "message_id": "01963d8a-6f2c-7d4e-9b1a-3c5e8f2a7b10", "replayed": false } ``` A `202` means that PostHog queued the email, not that it was delivered. Keep the `message_id` to [check the status](#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](https://posthog.com/docs/workflows/transactional/templates.md). Send `template_id` and `message_data` in place of `template_key`, `subject`, and the body: ```bash curl -X POST "https://us.posthog.com/api/messaging/send/email/" \ -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: welcome-email-9a41c20b" \ -d '{ "template_id": "", "to": "jane@example.com", "distinct_id": "user_123", "message_data": { "first_name": "Jane", "reset_link": "https://example.com/reset?token=abc123" } }' ``` `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). ```bash curl "https://us.posthog.com/api/messaging/emails//" \ -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" ``` If you lost the response of a send, read the status by its idempotency key instead: ```bash curl "https://us.posthog.com/api/messaging/emails/status/?idempotency_key=password-reset-8f14e45f" \ -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" ``` A found email returns `200`: ```json { "id": "01963d8a-6f2c-7d4e-9b1a-3c5e8f2a7b10", "status": "delivered", "created_at": "2026-10-28T16:27:44.364000Z", "status_at": "2026-10-28T16:27:49.625000Z", "reason": null } ``` 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](https://posthog.com/docs/workflows/transactional/status.md) for what each value means. ## Next steps | To do this | Read | | --- | --- | | See every field, response, and operational error code | [Transactional email API](https://posthog.com/docs/api/transactional-email.md), [email logs API](https://posthog.com/docs/api/email-logs.md), and [retries and errors](https://posthog.com/docs/workflows/transactional/retries-and-errors.md#what-to-retry) | | Build a production integration | [Send emails from code](https://posthog.com/docs/workflows/transactional/send-from-code.md) | | Attach files and inline images | [Attachments](https://posthog.com/docs/workflows/transactional/attachments.md) | | Protect login links and turn off tracking | [Sensitive data](https://posthog.com/docs/workflows/transactional/sensitive-data.md) | | Handle errors, retries, and idempotency keys | [Retries and errors](https://posthog.com/docs/workflows/transactional/retries-and-errors.md) | | Check rate limits and quotas | [Limits, quotas, and sending tiers](https://posthog.com/docs/workflows/reference/limits.md#api-and-sdk-limits) |