Repository navigation
feat(emails): add Category to code sends - #378
Conversation
SendCodeEmailOptions.Category sends an email from code as marketing email in one of the project's message categories, named by its key. Left out, the body carries no category and PostHog sends transactional email as before. EmailCategories.Transactional names the built-in value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael Decisions:
|
There was a problem hiding this comment.
PostHog Review · Standard · reviewed c6bcde2: 1 Should fix.
See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.
posthog-dotnet Compliance ReportDate: 2026-12-02T07:18:59.296789+00:00 ✅ All Tests Passed!47/47 tests passed Capture Tests✅ 30/30 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
SDK performance: posthog-dotnetBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Compared 108 metric rows; 108 rows shown in all results. Omitted or shortened data remain in |
The send API now takes a category object, upserted by key, or the string "transactional". SendCodeEmailOptions.Category becomes a MessageCategory with Key, Type, Name and an optional Description; MessageCategory.Transactional is sent as "transactional". It replaces EmailCategories. A blank key or name, or an undefined type, throws before any request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael Decisions for contract revision 2, replacing the earlier lines:
|
The send API keeps a category's description when the field is missing and clears it when it is "". Pin that the SDK leaves description out only when it is null, and document both on MessageCategory.Description. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The category tests compared the sent JSON text. They now send through PostHogClient to an in-memory fake of the send endpoint that keeps the project's categories: it upserts by key, refuses a type change with category_mismatch, keeps a description when the field is missing and clears it on an empty string. The tests check what the fake stored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael One more decision, from the review of
|
…egory A code send whose template key names a template in a category follows that template's category when Category is left out, and PostHog refuses MessageCategory.Transactional for it with category_mismatch. The fake send API now models that, two tests check both outcomes, and the docs name the template exception instead of calling the two the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A template in a transactional category is sendable on every backend layer, so the inherited category and the category_mismatch refusal hold whether or not marketing template sends are on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael One more decision, from the backend's template rule (PostHog/posthog#132118):
|
A send whose template key names a template sends in the template's category, so it neither creates nor updates the MessageCategory it names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t creation A code send that names a category now creates it when the project has none with that key, and otherwise leaves it as it is. The docs, the changeset and the fake send endpoint stop describing a send that renames a category or keeps or clears its description, and the docs name the 400 codes a caller branches on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael One more decision, from the redesign of the send category on 2026-11-12 (PostHog/posthog#132118):
|
PostHog accepts a marketing email's HTML only with a link whose href is the unsubscribe placeholder. The fake send endpoint now refuses a bare placeholder, the category fixture carries a link, and the docs and changeset say a link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Templates made in PostHog are transactional. PostHog refuses a send under a template in a marketing category with marketing_template, and refuses unsubscribe_link_required and copies_not_allowed only on marketing code sends. The docs and the test fake now say and do the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Claude Opus 5.5 responding on behalf of Michael One more decision, from the send category work on 2026-11-12 (PostHog/posthog#132118):
|
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
…ys, test named transactional key, broaden deferral doc
PostHog takes `category` on a code send as the key of an existing message category, not an object. Drop MessageCategory and MessageCategoryType, make SendCodeEmailOptions.Category a string, and refuse a blank key before any request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…egory body Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hment code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR overviewNo security issues were found in this pull request. Reviews
|
There was a problem hiding this comment.
Approved.
The disclosed API and send-path changes have current-head independent review and a STRONG-familiarity author, with targeted regression tests. No concrete unresolved review concerns or other refusal grounds are present; backend rollout claims cannot be independently verified from this checkout.
- Author wrote 100% of the modified lines and has 3 merged PRs in these paths (familiarity STRONG).
- PostHog Review (Standard) reviewed the current head: no findings.
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| every_file_attested | ✓ | not a bot PR |
| size | ✓ | 33L, 3F substantive, 99L/6F incl. size-exempt files — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (99L, 6F, cross-cutting, feat) |
| stamphog 2.11.0 | .stamphog/policy.yml @ 02f0bd0 · reviewed head 02f0bd0 |
…416) * revert(emails): remove Category from code sends This reverts commit b083162 (#378). Code-sent emails are staying strictly transactional, so message category support on code sends is being reverted. The recent release shipped shortly before this decision while the server feature flag was disabled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(emails): add a patch changeset for the Category revert Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(emails): keep Category as obsolete and refuse it before any request Code-sent emails are transactional only. Keep SendCodeEmailOptions.Category in the public API, marked [Obsolete], so code built against 2.31 still compiles and loads. A send that sets it throws an EmailException with the code invalid_form and the field category before any request, pointing marketing email to a PostHog workflow. The SDK never sends a category, and a null Category sends exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(emails): refuse Category before any other check A categorized send with another invalid option now still gets the invalid_form refusal with workflow advice, and no file is uploaded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs(emails): note CS0618 fails builds that treat warnings as errors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

💡 Motivation and Context
Emails.SendAsynccan't put the email in a message category.Depends on PostHog/posthog#142574 and PostHog/posthog#142564, both merged and live in US and EU, with the flag
workflows-code-send-categoriesat 100%.Changes:
SendCodeEmailOptions.Categorytakes astring?: the key of one of the project's message categories, such asnewsletter.categoryas that string only when it is set. Left unset, the body has nocategory, so every send without it keeps today's exact body.ArgumentExceptionbefore any request, like a blankReplyToaddress. The server owns the key format and length.categorystays off template sends (SendTemplateEmailOptions), where the template's own category applies.{{ unsubscribe_url }}with the recipient's preferences link, and adds List-Unsubscribe headers. A marketing email can't haveCcorBcc. PostHog refuses a send withcategory_not_found,marketing_copies_unsupported(marketing with copies),workflow_can_wait(marketing with attachments) orsandbox_fields_unsupported(marketing from the PostHog test sender), which reach the caller asEmailException.Code.Note
Public API change: new
SendCodeEmailOptions.Category(string?). Additive.Note
🔵 Merge risk: low · two-way door at merge, one-way door once released via NuGet: a published package version commits
SendCodeEmailOptions.Categoryas public APICategoryafter a NuGet release change. Every send without it keeps today's exact body, covered by the existing exact-body tests inEmailsTests.ArgumentExceptionbefore any request.categoryas a key string, live at 100%. An older server refusescategorywith a 400 field error, so the send fails loudly and never drops the field.workflows-code-send-categories. Once released, fix forward in a new NuGet release.Rollout
workflows-code-send-categoriesat 100%. This PR stays a draft until one real send through this branch passes, then a separately approved NuGet release.💚 How did you test it?
SendsTheCategoryKeyWhenSetparses the body and asserts every field, withcategoryas the JSON stringnewsletter. The existing exact-body tests, such asSendsTheRenderedContentWithoutUnsetFields, show a send withoutCategorycarries nocategory.ReportsARefusedCategoryAfterOneRequestanswers a categorized send with 400category_not_foundorsandbox_fields_unsupported, and asserts the caller gets that code asvalidation_erroroncategoryafter one request.RefusesInvalidContentBeforeAnyRequestgains a whitespaceCategoryrow.body["category"]line and the blank check turned both tests red.mcr.microsoft.com/dotnet/sdk:10.0) after mergingmain:dotnet restore --locked-mode,bin/fmt --checkanddotnet build --configuration Releasepassed, andUnitTestspassed onnetcoreapp3.1,net8.0andnet10.0.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) built
Category. Antigravity (Gemini 4 Neon) mergedmainand applied doc and test fixes on the earlier design. The first design sent a category object (key,type,name,description) or a built-in"transactional", with create and restore on send. The merged server takes a plain key string instead, so this head dropsMessageCategory,MessageCategoryType, the object validation and the tests that guarded them.categorycarry?category?Involvement: 3-lens review panel, Hedge final reads, ReviewHog; live-run proof owed.
🤖 Generated with Claude Code
How did you test this code?
c6bcde2to02f0bd002f0bd0End table: no gate at HEAD yet. Run hedge proof gate, then hedge proof receipt.
Not checked: none recorded
Full receipt: https://artifacts.posthog.com/a/ITtOCMlcJGpc5i8yW8Y9vd