5.62.0
Minor Changes
-
#5509
71c2464Thanks @Silthus! -posthog.emails.send()can now send email content your code rendered, such as HTML from React Email. Give the email atemplateKeyand asubject, and passhtml,textor both.const posthog = new PostHog("phc_...", { secretKey: "phs_..." }); const { data, error } = await posthog.emails.send({ to: "user@example.com", distinctId: "user_123", templateKey: "password-reset", subject: "Reset your password", html: renderedHtml, }); if (error) throw error; // 'delivered', 'bounced', ... const { data: status } = await posthog.emails.get(data.id);
You need a project secret API key, the kind that starts with
phs_. Create one under Project secret API keys in your project settings. Set its Transactional email scope to Write to send emails, or to Read for a key that only reads statuses. Pass it to the client assecretKey. SetappHostto your PostHog app URL when you self-host PostHog or send through a reverse proxy.PostHog records each email's delivery, opens and clicks on the person with that
distinctId. It groups every email with the sametemplateKey, so you see their metrics and logs in one place. The SDK retries a request that hits a network error, a rate limit or an outage twice by default. Every send carries an idempotency key, so a retry never sends the email twice. Pass your ownidempotencyKey, such aswelcome:user_123, and your job runner's retries are safe too.A send with your own content also takes
from,replyToandcaptureEngagement: false. SetmigratedFromon the client to tell PostHog which email provider you moved from. A failed call returns anEmailErrorwith PostHog'scodeand the HTTPstatusCode.Docs: Send transactional emails with Node.js and the transactional email overview. (2026-11-05)