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 email

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

Guided tutorial promptsending-transactional-emails
“Walk me step by step through sending my first transactional email in this repo. Before each step, briefly explain what it does (project secret API key, test sender vs. verified domain, idempotencyKey, and distinctId). Start with the PostHog test sender to my own PostHog account email, stop after the first send so I can verify it in my inbox and in PostHog's Log tab, and do not switch to a live user list until I confirm.”

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-node or posthog.

Checkpoint 2: The first send

What the agent explains:

  • templateKey – names the email, such as welcome. 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.

What you learned

  • A project secret API key with the transactional_email:write scope 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

Still have questions?

Was this page useful?