Send to many recipients

Send one transactional email to up to 100 recipients in one request, such as a weekly digest or an alert to each member of a team. Each recipient gets their own email, with its own message ID, statuses, and events. It's the same email that a single send to that recipient makes.

Batch sends are for emails each person needs. To send marketing to an audience, use a broadcast instead, so opt-outs apply.

Send a batch

Name a template in PostHog with its template ID. Pass the data that every recipient shares once, and each recipient's own data next to them. A recipient's data is merged over the shared data: a top-level key that a recipient sets replaces the same key in the shared data.

const { data, error } = await posthog.emails.batch(
{ templateId, templateData: { team: "Hedgebox" } },
[
{
to: "ada@example.com",
distinctId: "user_123",
idempotencyKey: "digest-2026-49-user_123",
templateData: { first_name: "Ada" },
},
{
to: "alan@example.com",
distinctId: "user_456",
idempotencyKey: "digest-2026-49-user_456",
templateData: { first_name: "Alan" },
},
]
)

FieldRequiredWhat it does
template_idYesThe template that every recipient gets.
message_dataNoData that every recipient shares (templateData or template_data in the SDKs).
recipientsYes1 to 100 recipients.
recipients[].toYesThe recipient.
recipients[].distinct_idNoThe recipient's distinct ID, so the send lands on their person. See link emails to your users.
recipients[].message_dataNoThis recipient's data, merged over the shared data.
recipients[].idempotency_keyYes in the APIA key for this recipient's email, different for each recipient. The SDKs make one when you leave it out. See idempotency keys.

A batch request has no Idempotency-Key header, because each recipient has its own key. A batch doesn't take scheduled_at, cc, bcc, attachments, headers, or tags. Send those emails one at a time with a single send.

Send the same content from code

To send the same content to every recipient, replace template_id with the fields of a code send: template_key, subject, and html or text. A batch also takes from, reply_to, sensitive, and tracking. Each recipient gets the same content, so a recipient can't have its own message_data. The SDK batch methods take these fields too.

Read the results

PostHog returns 200 with one result for each recipient, in the order of the request. One recipient can fail while the others are queued:

JSON
{
"results": [
{"message_id": "0192a4c8-5b2e-7d3f-8a1c-2e4f6b8d0a1c", "status": "queued", "replayed": false},
{"message_id": "0192a4c8-6d1a-7e2b-9c3d-4f5a6b7c8d9e", "error": {"code": "recipient_suppressed", "detail": "...", "status": 422, "retryable": false}}
]
}

Each result has a message ID, also when it has an error. Use it to check the status of that email. PostHog derives the ID from the recipient's idempotency key. So an error's ID doesn't prove that this recipient's email was queued: when an earlier email used the same key, the ID names that earlier email. An error has the same codes as a single send, such as recipient_suppressed. See retries and errors.

The SDKs return a result for each recipient too, with the recipient's position, address, idempotency key, and a status. It has a message ID when PostHog returned one. Without one, look the email up by its key.

StatusWhat it meansWhat to do
queuedPostHog accepted the email.Nothing. Check its status later, as for a single send.
failedPostHog didn't queue the email. The error says why, such as a suppressed address.Fix the cause before you send it again.
unconfirmedThe SDK can't tell if PostHog queued the email, such as after a lost response. It can still go out.Send it again with the same email and the same idempotency key, within 24 hours of the first request that used the key. The key stops PostHog from sending it twice. If the resend is unconfirmed too, send it again the same way within those 24 hours. After 24 hours, look it up by its key first.

In the API, a result error with "retryable": true is the same as unconfirmed. Its code is delivery_unavailable.

When the whole batch fails

PostHog refuses some requests as a whole, such as when the project is over its email quota, or the email is paused. The response then has an error and no results. The SDKs return the error with a result for each recipient.

StatuscodeWhat to do
413content_too_largeThe batch is larger than PostHog takes at once. Split the recipients into smaller batches.
400content_too_largeThe shared content or message_data is over 256 KiB. Smaller batches don't help. Make it smaller, or send those emails one at a time.
429throttledThe batch would go over the send rate limit. Each recipient counts toward it. Wait for the time in the Retry-After header.
503delivery_unavailablePostHog didn't confirm the batch, so some of its emails can still go out. Send the same batch again, with the same idempotency key for each recipient, within 24 hours.

When a response is lost, or PostHog refuses a retry of a batch whose first response was lost, some emails can still go out. Send the same batch again within 24 hours, with the same template, data, recipients, and keys. Or look each email up by its key. Within one call, the SDKs mark these recipients as unconfirmed. A new call that PostHog refuses reports them as failed, even when an earlier call queued their emails.

If the retry gets batch_unavailable or a 404, another batch gets the same answer, and the refusal doesn't prove that the earlier request sent nothing. For a batch with template_id, check the template ID. Then, within 24 hours of the first request with each key, send each recipient on its own with a single send that repeats the batch's email exactly: the same address, distinct ID, and key, and the same template ID with the merged data, or the same template_key, content, and options. After 24 hours, look each email up by its key instead.

The SDKs retry a batch for you after a network error, a rate limit, or a 503, with the same key for each recipient.

Idempotency keys

Build each recipient's key from the record that the email is for, such as digest-2026-49-user_123 for one person's digest of one week. Then a new run of the same job makes the same keys, and PostHog doesn't send an email twice, as long as it still keeps the keys. Never build a key from the time of the run.

PostHog keeps a key for 7 days. The SDKs tell you to send an unconfirmed email again within 24 hours of the first request with its key, so rerun a job within 24 hours. After PostHog drops a key, a send with it can make a second email. A lookup that finds no email doesn't prove that a resend is safe.

  • Different for each recipient. Two recipients with the same key fail the whole batch with 400.
  • Made by an SDK. A key that an SDK makes covers only its own retries in that call. When a job can stop and run again, pass keys that you build.
  • Shared with single sends. A batch recipient and a single send with the same key and the same email are one email.

For the other rules of idempotency keys, see retries and errors.

Limits

  • 100 recipients a request. For more, send more batches. The SDKs return an error for more than 100 recipients, and send nothing.
  • 5 MiB a request. The shared content and message_data can be up to 256 KiB.
  • Rate limits. Each recipient counts toward the project's send rate limit, the same as a single send.

Still have questions?

Was this page useful?