Repository navigation
Conversation
Add IPostHogClient.Emails, a port of posthog-node's and posthog-python's emails API. SendAsync sends a template made in PostHog by its ID, or content the app rendered, named by a template key, as the flat body of POST /api/projects/@current/messaging/send/email/. GetAsync reads an email's status. Every attempt of a send carries the same idempotency key. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Serialize read-only dictionaries without recursing into the same converter, so ReadOnlyDictionary template data no longer overflows the stack. - Give IPostHogClient.Emails a default implementation where the target allows it, as EvaluateFlagsAsync does, so custom implementers keep compiling. - Drain email requests while the event batch flushes, instead of before it. - ConfigureAwait(false) on every await in EmailSender, so a synchronous Dispose can't deadlock on a captured context. - Name an invalid AppHost in the missing_app_host message. - Drop the unused jitter seam, the unreachable body-read fallback and the inline comments; use UUID message IDs in the send fixtures. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copy the entries into a Dictionary and let System.Text.Json's own dictionary converter write them, so non-string keys keep their JSON property-name format. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Write one property per entry the source enumerates, with the key type's own JSON property-name converter, instead of copying into a Dictionary whose default comparer could merge keys the source keeps apart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
System.Text.Json's string converter already applies DictionaryKeyPolicy, so a custom string key converter keeps working with a naming policy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adding Emails to IPostHogClient broke custom implementers on netstandard2.0, which has no default interface members. Emails now lives on PostHogClient, and AddPostHog registers the client's IPostHogEmails for injection. Dispose() runs DisposeAsync off the caller's synchronization context, so a synchronous dispose on a single-threaded context can't deadlock while an email request or the event flush is still running. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omments Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
posthog-dotnet Compliance ReportDate: 2026-11-04T08:19:28.504137+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
|
Also move the older-server note to the SendCodeEmailOptions remarks, so it shows for Cc and Bcc too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
|
@PostHog review |
Contributor
|
@Silthus PostHog Review is reviewing this pull request. |
Silthus
marked this pull request as ready for review
November 4, 2026 08:38
4 of 5 tasks
dustinbyrne
approved these changes
Nov 4, 2026
stamphog
Bot
dismissed
their stale review
November 5, 2026 12:09
The PR was retargeted to a different base branch, so the approved diff is no longer what was reviewed. Stamphog re-reviews automatically.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
An email sent from code often needs a copy to someone else, or a file such as an invoice or a receipt. The .NET SDK's code send takes neither, so a .NET app has to fall back to hand-written HTTP for those emails. This PR adds
Cc,BccandAttachmentstoSendCodeEmailOptions. It matches posthog-node (PostHog/posthog-js#5514) and posthog-python (PostHog/posthog-python#1172), against the server contract in PostHog/posthog#127988.Stacked on #365, which adds
PostHogClient.Emails.Impact
No metric: the SDK emits no events, and the server's send logs (#127988) are where code sends with copies or attachments show up. It pays into Grow Workflows.
Merge risk
Note
Low risk, one-way door (public API). The change is additive: three new optional properties on
SendCodeEmailOptionsand a newEmailAttachmentclass. Once released, they are API that customers compile against. A send that leaves all three out sends the same body as before.Release order. These fields need the server side deployed: PostHog/posthog#127988 (Django), plus #127985, #127995 and #127986 (cdp-api and the email workers). They sit on top of #127122 and #127123, which #365 already waits for. Until they deploy, a send with any of the three fields is refused with a
validation_errorthat names the field. Don't merge or release this until sends with these fields are live and usable for customers, which is later than the server deploy.What it does
SendCodeEmailOptionsgets:CcandBcc: lists of bare addresses, at most 10 each;Attachments: a list ofEmailAttachment, at most 10 and 512 KB in total.EmailAttachment. It holds:Filename: required, the name the recipient sees;Content: required, the bytes asReadOnlyMemory<byte>, sent as standard Base64;ContentType: optional MIME type;ContentId: optional, shows the file inline ascid:<id>.cc,bccandattachments: [{filename, content, content_type?, content_id?}]. An empty list is left out of the request, as in posthog-node.ArgumentExceptionbefore any request, like the code form's other option checks:CcorBcc;Filename.EmailExceptionwithName = validation_errorandFieldset to the field it refused.Divergence from sdk-specs.
openspec/specs/emails/spec.mdin PostHog/sdk-specs covers only the template form, with no code form, copies or attachments. This follows posthog-node and posthog-python. One .NET-specific choice:Contenttakes bytes only, while the other SDKs also take a Base64 string (see the decisions below).💚 How did you test it?
Everything below ran at head
493972e.Live run against the real server. The stack was feat(messaging): send cc, bcc and attachments on a code send posthog#127988 (Django,
e09eec3e49f) and #127986 (cdp-api and the email workers,a239b6bbc48, with #127995 and #127985 below it), plus a mail catcher and a recording proxy in front of Django. A console app drove this branch'sPostHogClient. Every case matched:Cc, twoBcc, a PDF (ContentTypeapplication/pdf) and a PNG (ContentIdlogo)202. One message reachesto, the cc address and both bcc addresses. TheCc:header lists the cc address, and no header shows a bcc address. The PDF arrives as an attachment and the PNG inline asContent-ID: <logo>, and each file's sha256 matches the bytes sent.GetAsyncon that IDsentReplayed = true, the same ID, and no second mailCc,BccandAttachmentsall empty202, and the request body has none of the three keystool.exe400→validation_error,Fieldattachments__0__filename, withWhyandFix400→validation_error,Fieldattachments: at most 512 KB in totalCc = ["Jane <[email protected]>"]400→validation_error,Fieldcc__0: a bare address onlyBccaddresses400→validation_error,Fieldbcc: at most 10None of the refused sends delivered mail. The readback found the Cyclotron job, the
email_statusrow and the idempotency key in Valkey. A snapshot of the attachments table while the job was queued showed both files, with sizes and sha256 that match the bytes sent. After the send the table holds no rows for the team.Cross-version: a server without this change. Each setup sent the attachments case and a
Cc-only send:eb265457934): both are refused with400→validation_error,Fieldcc, "PostHog doesn't take this field yet, so it didn't send the email."213fad657c0): both are refused with400→validation_error,Fieldattachmentsorcc, "PostHog doesn't take this field, so it doesn't send the email without it."In both setups no job is queued and no mail goes out, as the XML docs and the changeset say. A server older than #127123 refuses every code send, as feat(emails): send transactional email with client.Emails #365's cross-version run showed.
CI on
493972e: build, format, tests on netcoreapp3.1 and net8.0, packaging, and the SDK compliance tests all pass. The repo's build workflow only runs on its own for PRs intomain, so I started it on this branch by hand. CodeQL can't be started by hand, so it runs once feat(emails): send transactional email with client.Emails #365 merges and this PR targetsmain.Lane gate on
493972e, with the CI steps run locally:dotnet restore --locked-mode,bin/fmt --check,dotnet build -c Release,dotnet test -c Release(1649 passed on net8.0, 1639 on netcoreapp3.1). Exit 0.Unit tests.
tests/UnitTests/Emails/EmailsTests.csdrives a realPostHogClientthroughEmails.SendAsync, with a recordingHttpMessageHandleras the only fake.SendsCopiesAndAttachmentschecks the exact request body, including the Base64 of a slicedReadOnlyMemory<byte>and of a whole array.LeavesOutEmptyCopyAndAttachmentListschecks that empty lists add no keys.InvalidCodeSendscovers a blankCcandBccaddress, a null attachment, and a blankFilename. Each one throws before any request.Server-side observation, not an SDK defect. As on feat(emails): send transactional email with client.Emails #365, the status route answered
404for the first poll 76 ms after the202, andsent2 s later.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file (.changeset/emails-cc-bcc-attachments.md, minor)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Built by Claude Opus 5.5 (
claude-opus-5-5, high effort) in Claude Code, directed by Michael as one slice of the transactional-email-from-code work, to bring every server SDK to parity with posthog-node and posthog-python.Reviewed by a cross-model panel: GPT-6.1 Sol on correctness, risk, design and anti-overengineering, Claude Opus 5.5 on fresh eyes, then a narrow second round and a final read on GPT-6.1 Sol. Fixed: System.Text.Json now writes the attachment Base64, replacing a hand-written helper with per-target branches; the older-server note moved to the class remarks, so it shows for
CcandBcc; one comment removed. Rejected: a shadow diff, because a send without the new fields produces the same body as before, which the existing exact-body tests pin. The claim that an older server refuses the fields was checked in the server code and then shown by the cross-version run.cc,bccandattachments, as in posthog-node, posthog-python and the server contractReadOnlyMemory<byte>only. The other SDKs also take a Base64 string, but a .NET caller with one callsConvert.FromBase64String, and a typed byte buffer can't be a malformed string. Arrays, slices and pooled buffers all fit without a copyArgumentExceptionlike the other option checks. Limits, file types and formats stay on the server, so they change in one placeInvolvement: no grilling rounds, no prototypes, 2 review rounds (one 5-lens panel, one 3-lens fixes round) and 1 clean final read, and live-run plus cross-version proof captured.
🤖 Generated with Claude Code