Send transactional emails with Go
The Go SDK sends transactional emails. This page uses the v2 module, and every v2 release can send. On the v1 module, sending needs 1.40.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.
When SecretKey is set, the client also polls flag definitions with it for local evaluation. Give the key the Feature flag read scope too, or the client logs a failed poll each time it polls.
Close the client 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 returns a *SendEmailResult and an error. result.ID is the message ID. A result means PostHog queued the email, not that it delivered it. Every error is a *posthog.EmailError. Read it with errors.As, and branch on its 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 html/template, and pass the result as HTML. See send emails from code for what each field does and the checks PostHog runs.
Send takes a posthog.CodeEmail for an email that your code writes, and a posthog.TemplateEmail for a template from PostHog. See send emails from code for every field, and the quick start for the version each one needs.
Write automated tests
Start an httptest.Server and set its URL as both Endpoint and AppHost, to see exactly what your code sends with no request to PostHog. The server uses http, so also set AllowInsecureAppHost. 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 a
posthog.TemplateEmailwithTemplateIDandTemplateData - Send from a job queue, with the client's retries off
- Check an email's status
- SDK reference for every method and option





