Send transactional emails with Node.js
The Node.js SDK sends transactional emails from version 5.62.0. Your code sends the subject and HTML, so the email lives in your codebase.
You need a project secret API key. Until you verify your domain, emails go only to your team, from the test sender. To see an email in your inbox first, follow the quick start. New to sending from code? Read send emails from code.
Prompt for your coding agent
Paste this into Claude Code, Cursor, or another coding agent. It sends the agent to this page and gives it the rules that agents often get wrong.
Install
Set up the client
Add your project secret API key to the PostHog client that your app already has. The project token keeps capturing events. The secret key sends email, so keep it on your server and never ship it to the browser.
Keep enableLocalEvaluation: false unless this client also evaluates feature flags locally. With local evaluation on, the client polls flag definitions with the secret key, and a key with only the Transactional email scope can't read them. If you do evaluate flags locally with this client, give the key the Feature flag read scope too.
Shut the client down when your app exits, not after each send. If your app sends through a reverse proxy or a self-hosted PostHog, set appHost to your PostHog app URL. The client never sends email requests to a host that might be a proxy.
Send an email
send doesn't throw. It returns { data, error }. data.id is the message ID. data means PostHog queued the email, not that it delivered it. error is an EmailError, and its code is one of the codes in the errors table.
Fields use camel case, such as templateKey and distinctId. See send emails from code for every field, and the quick start for the version each one needs.
Send React Email components
From version 5.69.0, you can pass a React Email component as react, in place of html. The SDK renders its HTML and plain text with @react-email/render, which you install next to posthog-node. If you bundle your app, such as for Cloudflare Workers or Vercel Edge, also pass reactEmailRenderer: await import("@react-email/render") to the client.
See React Email for the errors that a React send can return.
Write automated tests
Pass your own fetch to see exactly what your code sends, with no network call. This tests your integration, not delivery. To test delivery, send a real email to your own address and check the Log on the Transactional tab.
Next
- Attachments, copies, and open and click tracking
- Link emails to your users
- Send a template from PostHog, with
templateIdandtemplateData - Send from a job queue, with the client's retries off
- Check an email's status
- SDK reference for every method and option





