Send transactional emails with Rust
The Rust SDK sends transactional emails. This page uses the posthog crate, and every release from 1.0.0 can send. On the older posthog-rs crate, sending needs 0.31.0 or later. 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.
The client loads flag definitions only when you turn on enable_local_evaluation. If you do, give the key the Feature flag read scope too.
Without the default async-client feature, the client and emails() are blocking, and you call them without .await.
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 app_host to your PostHog app URL. The client never sends email requests to a host that might be a proxy.
Send an email
send returns Result<SendEmailResult, EmailError>. result.id is the message ID. An Ok means PostHog queued the email, not that it delivered it. Branch on error.code(), one of the codes in the errors table. A wrong argument, such as a template ID that isn't a UUID, returns an EmailError before any request.
For a longer email, render the HTML first with your template engine, such as Askama or Tera, and pass the result to html. See send emails from code for what each field does and the checks PostHog runs.
send takes a CodeEmail for an email that your code writes, and a TemplateEmail for a template from PostHog. After new, each field is a builder method. See send emails from code for every field, and the quick start for the version each one needs.
Write automated tests
Start a local stub server with httpmock and set its URL as app_host, to see exactly what your code sends with no request to PostHog. 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
TemplateEmail::newandtemplate_data - Send from a job queue, with the client's retries off
- Check an email's status
- SDK reference for every method and option





