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: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, 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.

Terminal
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": "<p>Hi Jane,</p><p><a href=\"https://example.com/reset?token=abc123\">Reset your password</a>.</p>",
"from": "Hedgebox <security@example.com>"
}'
  • to: one recipient for each request.
  • distinct_id: optional. The distinct ID that you pass to identify(). 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:

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. 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:

Terminal
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": "<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).

Terminal
curl "https://us.posthog.com/api/messaging/emails/<message_id>/" \
-H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY"

If you lost the response of a send, read the status by its idempotency key instead:

Terminal
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 for what each value means.

Next steps

To do thisRead
See every field, response, and operational error codeTransactional email API, email logs API, and retries and errors
Build a production integrationSend emails from code
Attach files and inline imagesAttachments
Protect login links and turn off trackingSensitive data
Handle errors, retries, and idempotency keysRetries and errors
Check rate limits and quotasLimits, quotas, and sending tiers

Still have questions?

Was this page useful?