Send your first transactional email
In this tutorial, you send one transactional email from your code, read it in your inbox, and find it on your own person in PostHog. You learn what the secret API key, the test sender, the idempotency key, and the distinct ID each do.
Before you start
- A PostHog account – you send the first email to the address you use to log in.
- A server project or a terminal – any Node.js or Python app works, or
curl. - No domain yet – until you verify a domain, PostHog sends from the PostHog test sender, which only emails members of your PostHog organization. You can't email a real user by mistake.
Send the email
Pick how you want to learn. Both paths reach the same checkpoints.
Start the agent
Pick one way to start:
Option A: run the wizard. From your server project, run the wizard. It creates the key, installs the SDK, and writes the first send for you.
Send your first email
npx @posthog/wizard emailOption B: connect the PostHog MCP and learn step by step. Run npx @posthog/wizard mcp add to connect the PostHog MCP to your agent. Then copy this prompt into your agent:
The agent stops at each checkpoint below. Check what you see before you tell it to continue.
Checkpoint 1: The secret key and the SDK
What the agent explains: a project secret API key starts with phs_. With the transactional_email:write scope, it can send email, upload attachments, and read the status of a send, and nothing else. It stays on your server, in an environment variable such as POSTHOG_PROJECT_SECRET_API_KEY.
What you should see:
- A new key in Project secret API keys, with Transactional email set to Write.
- The key in your environment, not in your code or in a commit.
- The PostHog SDK in your dependencies, such as
posthog-nodeorposthog.
Checkpoint 2: The first send
What the agent explains:
templateKey– names the email, such aswelcome. Each key shows as one email in PostHog, with its own sends and metrics.idempotencyKey– if your code retries the same send, PostHog sends the email only once.distinctId– links the email to a person, so its events land next to everything else they did.
What you should see: the agent runs the send to your PostHog account email, and PostHog returns 202 with a message ID. 202 means queued, not delivered yet.
Checkpoint 3: Verify the delivery
What the agent explains: the test sender only emails members of your PostHog organization, and adds a footer that says so.
What you should see:
- The email in your inbox, from "your organization name via PostHog".
- In PostHog, go to Transactional and open the Log tab. Your send shows with its timeline: sent, then delivered.
- Open the send. It links to your person, with what you did before and after it.
Checkpoint 4: Get ready for real users
What the agent explains: to email real users, verify your sending domain. Your code doesn't change: once the domain is verified, sends move from the test sender to your domain.
What you should see: the agent stops here. It doesn't send to anyone else until you verify your domain and tell it to continue.
1. Create a secret API key
- Go to Project secret API keys, and click Create project secret API key.
- Set Transactional email to Write. This is the
transactional_email:writescope. - Copy the key. It starts with
phs_, and you only see it once. - Save it on your server as
POSTHOG_PROJECT_SECRET_API_KEY. Never ship it to the browser.
What you should see: the new key in the list, with the Transactional email scope.
2. Install the SDK
For Node.js:
For Python:
With cURL, you don't install anything.
3. Send to yourself
Replace you@example.com with the email you use to log in to PostHog, and user_123 with your own distinct ID. Until you verify a domain, the email goes out from the test sender.
With cURL, use https://eu.posthog.com if you log in to PostHog in the EU.
What you should see: a 202 response with a message ID. Send it again with the same idempotency key, and PostHog doesn't send a second email.
4. Verify the delivery
- Open your inbox. The email comes from "your organization name via PostHog", with a test sender footer.
- In PostHog, go to Transactional and open the Log tab.
- Open your send.
What you should see: the timeline of the send, from sent to delivered, and a link to your person, with what you did before and after the email.
5. Verify your domain
The test sender only emails members of your PostHog organization. To email your users, set up your domain.
What you should see: once your domain is verified, your next send comes from your own address. You don't change your code.
What you learned
- A project secret API key with the
transactional_email:writescope sends email from your server. - The test sender lets you test safely before you verify a domain.
- An idempotency key stops a retry from sending the same email twice.
- A distinct ID links each send to a person, and the Log tab shows its timeline.
Next steps
- Send emails from code – templates, attachments, and React Email.
- Reliable delivery – how retries, idempotency, and statuses work together.
- Marketing or transactional – which kind of email to send, and why it matters.
- Build your first automation – send emails that react to what people do.





