Repository navigation
fix(email): split the envelope sender by audience - #807
Conversation
Production dropped every transactional email: the sender resolved to `[email protected]`, and only the `cloud.` subdomain was verified in Resend, which refuses a send from an unverified domain. The adapter returns rather than throws on that refusal — deliberately, so a failed verification mail cannot roll back the manager-create transaction — so the drop reached nobody but Sentry. 108 in seven days. `CONTACT_EMAIL` was carrying three jobs at once: the envelope `From`, the `mailto:` shown to a human, and the default `To` for inbound forms. Only the first moves. `USER_EMAIL_FROM` (`[email protected]`) now sends registrant mail and `MANAGER_EMAIL_FROM` (`[email protected]`) everything aimed at a manager, a reviewer, or the admin inbox. The `to:` on each send already decides the audience unambiguously, so nothing new is threaded through. Fixing only the domain would have left seeker and manager mail going out under one identity, which is the half of #790 that was #805. The adapter's own defaults take the manager address, since the only sends that reach them name no `from` of their own: Payload's auth mail, the embed- verification notice, and the event-verification reminder. Its `defaultFromName` is now derived from the same brand `Managers.ts` builds the auth subject from, rather than the hand-written "We Meditate Admin" that matched no project label. Refs #790 Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014NUCzwJKoePwtkUy46fySC
A wrong sender is invisible in the body — only the header carries it, and the adapter drops the send silently when it is refused. So each sender gets its own assertion rather than a shared helper, and each compares against a constant so the audience it belongs to is what the spec states. `email-sender-addresses.spec.ts` covers the five directly-callable senders with a stub payload; its `findGlobal` rejects on purpose, which falls `resolveEmailStrings` back to the English defaults. `sendFollowUp` is unexported, so the job is the only seam its envelope is visible from and the assertion goes in `event-feedback.int.spec.ts` beside it. Both directions were verified red before this landed: swapping one user-facing sender to the manager constant and one manager-facing sender to the user constant failed exactly the two matching cases. A final case asserts the two constants differ, since every other assertion compares constant to constant and would stay green if they collapsed to one address. `send-user-message.spec.ts` was the vacuous case: its `from` assertion named `CONTACT_EMAIL`, which shares a default value with the manager address, so it passed before and after the repoint. It now names the constant it means and rejects the other one. Refs #790 Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014NUCzwJKoePwtkUy46fySC
`docs/rules/email.md` claimed one sender in four places. The new table says which constant is a `From` and which is a `To`, and states the trap plainly: an envelope sender's domain must be verified in Resend first, because the adapter's non-throwing contract turns a refusal into a Sentry event and nothing else. `.env.example` gains both overrides, commented out — the defaults are production's intended values, so neither needs setting. Refs #790 Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014NUCzwJKoePwtkUy46fySC
Four review lenses over the branch diff. What changed: `tests/utils/sendEmailStub.ts` replaces two same-named `fakePayload` helpers that sat in `tests/unit/` with different shapes — the kind of pair where the next person patches one and leaves the other silently stale. `email-sender-addresses.spec.ts` becomes an `it.each` table, the house idiom here with 30 existing uses. Each row still spells out its sender, recipient and expected constant on one line, so nothing is hidden behind a helper. Its per-test `await import()` becomes a static import: with no `vi.mock` in the file the dynamic form bought nothing and billed five heavy module graphs to test time. Aggregate unit-lane test time drops 8.3s to 6.4s. The `<addr>` angle brackets replace a hand-rolled extraction regex. They pin the address to the envelope rather than the display name, which is what the regex was for, and keep the failure message readable. Two assertions came out as underivable-from-nothing: `not.toBe(USER_EMAIL_FROM)` on the adapter default and `not.toContain(USER_EMAIL_FROM)` on the user message both follow from the positive assertion beside them plus the constants-differ guard. Corrected rather than simplified: the adapter's comment claimed its defaults serve "Payload's own auth mail". Payload composes `defaultFromName` for auth mail only — `VerifyEmbeds` and the event-verification reminder omit `from` too and reach the bare-address fallback. Both are manager-facing, so the address is right and only the display name is absent. The comment and the fallback spec now say so. Refs #790 Co-authored-by: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014NUCzwJKoePwtkUy46fySC
|
🚅 Deployed to the SahajCloud-pr-807 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff is the ticket and nothing else — seven senders repointed by their to:, two constants, the adapter default, docs. No abstraction for one caller. One question, and it is about a knob rather than about the fix.
Findings
should-fix—NEXT_PUBLIC_on the two new senders buys nothing and turns the override into a rebuild.src/lib/contact/index.ts:23.
Checked
- Every
sendEmailsite, including the three the diff leaves alone:VerifyEmbeds.ts:130,channels/email.ts:59anddeliverContact.ts:73all address a manager, so the manager default is right for them. grep -rn CONTACT_EMAIL src/— no remaining use in afrom:position.- One
'use client'importer of@/lib/contact(ProjectSelectionPrompt.tsx:6), and it readsCONTACT_EMAILalone. getEmailBrand().productNameisWeMeditate Web, already the auth subject inManagers.ts:43,53.sendEmailStub.tsis unit-lane, distinct from int-laneemailTestAdapter.ts.maincarried one local stub, not two.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
|
One thread addressed, rebutted. No commit, nothing pushed — head stays
Nothing else waits on us. No 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
The reviewer overrules #790 §1: nothing in the browser sends mail, so `NEXT_PUBLIC_` bought the two sender constants nothing and cost a rebuild to repoint one — the exact situation the knob exists for. `USER_EMAIL_FROM` / `MANAGER_EMAIL_FROM` move out of `@/lib/contact`, which a client component reaches, into `src/plugins/email/senders.ts`, and their overrides lose the prefix and move to `ServerEnvSchema`. Left in `@/lib/contact`, an unprefixed read would take the compiled default in the browser while the server honoured the override — #760's shape. A `client-bundle-safety` row enforces the boundary rather than stating it: watched fail by importing the new module from `ProjectSelectionPrompt`, the one client entry that reads `@/lib/contact`. `CONTACT_EMAIL` keeps its prefix. It genuinely is browser-facing. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Lf7SgpjTy6ijar1rUsDKw8
|
One thread addressed, adopted. Pushed
Lean gate green — lint, both typechecks, 2133 unit tests — plus ⚠ The merge blocker is unchanged: both domains must read Verified in Resend first. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
…can post links (#854) * feat(email): send preview mail over Mailpit's HTTP API, so a routine can post links A Claude routine reaches the network only through an HTTPS proxy, so the preview scripts' SMTP send to Mailpit's TCP proxy timed out there (#807) and no loop PR could carry an email preview link (#847, #853). The capture transport now posts to Mailpit's `POST /api/v1/send` instead, authenticated with a send-only `MAILPIT_SEND_AUTH` (Mailpit's `MP_SEND_API_AUTH`), falling back to `MAILPIT_UI_AUTH` while no send credential is configured. The scripts no longer read `SMTP_URL`; the app still sends through it. Also records where previews get `SMTP_URL` from: production's service, where it is inert, since Railway copies production's variables into every PR environment. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * refactor(email): send preview mail with the Mailpit login, not a send-only one Mailpit holds nothing a read login could leak: a preview's database has no production rows, and production mail goes to Resend. So one credential, MAILPIT_UI_AUTH, serves the scripts, the reviewer and the routine, which can now open its own previews too. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Summary
wemeditate.compublishesp=rejectDMARC at 20%, so shipping the repoint first rejects one registrant email in five outright.CONTACT_EMAILwas doing three jobs. Only the envelopeFrommoves:USER_EMAIL_FROM([email protected]) for registrants,MANAGER_EMAIL_FROM([email protected]) for managers, reviewers and the admin inbox.src/plugins/email/senders.ts. Themailto:shown in the admin and on the event-verify page is unchanged, and so is the defaultTofor inbound forms.Changes
src/plugins/email/senders.ts— new, server-only. The two constants and their unprefixed overrides, exported from the@/plugins/emailbarrelsrc/lib/contact/index.ts—CONTACT_EMAILalone, whose JSDoc now says it is not aFromsrc/lib/env/server.ts—USER_EMAIL_FROM/MANAGER_EMAIL_FROMinServerEnvSchema, unprefixed.ClientEnvSchemais back to its four browser variablessrc/plugins/email/resendAdapter.ts— defaults take the manager address;defaultFromNameis derived from the brand rather than the hand-written "We Meditate Admin", which matched no project labelFrom stays CONTACT_EMAILcomments reworded, keeping the clause about whyReply-Toexiststests/unit/client-bundle-safety.spec.ts— aSERVER_ONLYrow for the new module, so the boundary is enforced rather than statedtests/utils/sendEmailStub.ts— one shared unit-lane payload stub, replacing two same-named local onesPreview
Fromheader on eachTest results
tsc --noEmit(src),tsc --noEmit -p tsconfig.test.json, 2133 unit testsevent-feedbackintegration green after the import move; the other three (session-reminders,registration-digests,user-submissions-review-lifecycle) were green on the prior head and are untouched by itManual verification
sydevelopers.comandwemeditate.comboth read Verified in Resend before merging.Fromis[email protected].Fromis[email protected].Email sent successfullyand noResend API errorline.Notes for reviewer
Two findings from the review pass that I deliberately did not act on. Each is your call, not mine:
Fromexpression is now written seven times. AregistrantFrom(brand)/managerFrom(brand)pair next togetEmailBrandwould centralise it and incidentally fixsendSubmissionReview.ts:33, the one site that omitsheaderDisplayName. I left it because the ticket says "no new plumbing" in as many words, and this is an outage fix. The omission is cosmetic, not an injection risk — that brand string is a static project label.AGENTS.mdsays to ask first.One finding I rejected: that
expect(USER_EMAIL_FROM).not.toBe(MANAGER_EMAIL_FROM)would turn CI red if an operator pointed both variables at one domain during an incident. CI does not inherit production env —vitest.config.mts'ssharedTestEnvsets the test environment explicitly and names neither variable.Detail
Why the prefix drop was a module move too. Dropping
NEXT_PUBLIC_while the constants stayed in@/lib/contactwould have re-armed #760:ProjectSelectionPrompt.tsxreaches that module, and Next substitutes onlyprocess.env.NEXT_PUBLIC_*, so the browser copy would silently hold the compiled default while the server honoured the override. Moving them behind aSERVER_ONLYrow makes that unreachable rather than merely unlikely, and the row was watched fail by importing the new module from that component.No Email previews section. The diff touches
src/plugins/email/, so the template asks for Mailpit links. The preview scripts cannot run from the routine's container: outbound SMTP times out, since egress is HTTPS-proxy only. The Railway preview is where a reviewer sees real messages, hence the Mailpit link above.Two send sites set no
fromand inherit the adapter default:VerifyEmbeds.ts:128andchannels/email.ts:59. Both are manager-facing, so the address is right. Payload composesdefaultFromNameonly for its own auth mail, so these two send a bare address with no display name — pre-existing, unchanged here, and now written down in the adapter comment and the fallback spec rather than left to be rediscovered.Fixture pre-mortem. The new spec assumes the two constants resolve to their compiled defaults, i.e. that nothing sets
USER_EMAIL_FROMorMANAGER_EMAIL_FROMin the test environment. Verified againstvitest.config.mts(sharedTestEnv, lines 23–37) and.env— neither names either variable.senders.tsreadsprocess.envrather thanserverEnv. Every otherserverEnvread insrc/sits inside a function. These are module-level constants, so aserverEnvread here would validate the whole server environment at import, in every consumer and every unit spec.ServerEnvSchemastill validates both formats when they are set.Every new assertion was watched fail. Swapping one user-facing sender to the manager constant and one manager-facing sender to the user constant failed exactly the two matching rows, both before and after the table rewrite. A green new test proves nothing on its own.
Adapter import weight.
resendAdapternow imports./brandfor the display name. Measured delta at config init: zero —payload.config.tsalready imports the@/plugins/emailbarrel, which already re-exports./brand, and already imports@/plugins/access,@/plugins/storageandgetServerUrldirectly. No import cycle: nothing in the brand graph reaches@/plugins/email.Scope. The ticket title names the unverified domain; the DNS and Resend side is already done and pending verification, so this PR is the code half only.
Closes #790
🤖 Written by the sydevs autonomous loop — see what this is