Skip to content

fix(email): split the envelope sender by audience - #807

Merged
sydevs-bot merged 5 commits into
mainfrom
claude/fix-790-email-sender-split
Sep 18, 2026
Merged

sydevs-bot merged 5 commits into
mainfrom
claude/fix-790-email-sender-split

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • ⚠ Do not merge until both domains show Verified in Resend. wemeditate.com publishes p=reject DMARC at 20%, so shipping the repoint first rejects one registrant email in five outright.
  • CONTACT_EMAIL was doing three jobs. Only the envelope From moves: USER_EMAIL_FROM ([email protected]) for registrants, MANAGER_EMAIL_FROM ([email protected]) for managers, reviewers and the admin inbox.
  • Both senders are server-only, in src/plugins/email/senders.ts. The mailto: shown in the admin and on the event-verify page is unchanged, and so is the default To for inbound forms.

Changes

  • src/plugins/email/senders.ts — new, server-only. The two constants and their unprefixed overrides, exported from the @/plugins/email barrel
  • src/lib/contact/index.ts — CONTACT_EMAIL alone, whose JSDoc now says it is not a From
  • src/lib/env/server.ts — USER_EMAIL_FROM / MANAGER_EMAIL_FROM in ServerEnvSchema, unprefixed. ClientEnvSchema is back to its four browser variables
  • src/plugins/email/resendAdapter.ts — defaults take the manager address; defaultFromName is derived from the brand rather than the hand-written "We Meditate Admin", which matched no project label
  • 7 send sites repointed by audience; 5 stale From stays CONTACT_EMAIL comments reworded, keeping the clause about why Reply-To exists
  • tests/unit/client-bundle-safety.spec.ts — a SERVER_ONLY row for the new module, so the boundary is enforced rather than stated
  • tests/utils/sendEmailStub.ts — one shared unit-lane payload stub, replacing two same-named local ones

Preview

  • Events list — publish one, then register through it to produce a registrant confirmation
  • Managers list — a password reset exercises the adapter default, which is the auth-mail sender
  • Mailpit inbox — where both land; check the From header on each

Test results

  • Lean gate: ✓ lint, tsc --noEmit (src), tsc --noEmit -p tsconfig.test.json, 2133 unit tests
  • Targeted specs: event-feedback integration 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 it
  • Build: N/A — Railway builds the preview

Manual verification

  1. Confirm sydevelopers.com and wemeditate.com both read Verified in Resend before merging.
  2. On the preview, register for a published event; the confirmation's From is [email protected].
  3. Trigger a manager notification for that registration; its From is [email protected].
  4. After deploy, check Railway logs for Email sent successfully and no Resend API error line.

Notes for reviewer

Two findings from the review pass that I deliberately did not act on. Each is your call, not mine:

  1. The same From expression is now written seven times. A registrantFrom(brand) / managerFrom(brand) pair next to getEmailBrand would centralise it and incidentally fix sendSubmissionReview.ts:33, the one site that omits headerDisplayName. 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.
  2. The silent-drop mechanism is untouched, and it is why this lasted weeks. The adapter still swallows every failure into a Sentry event, and this PR adds a second sender domain to that exposure while mitigating with prose. A boot-time check that the configured senders resolve to verified domains would make the next mismatch loud. I have not filed a ticket for it — this repo's AGENTS.md says 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's sharedTestEnv sets 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/contact would have re-armed #760: ProjectSelectionPrompt.tsx reaches that module, and Next substitutes only process.env.NEXT_PUBLIC_*, so the browser copy would silently hold the compiled default while the server honoured the override. Moving them behind a SERVER_ONLY row 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 from and inherit the adapter default: VerifyEmbeds.ts:128 and channels/email.ts:59. Both are manager-facing, so the address is right. Payload composes defaultFromName only 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_FROM or MANAGER_EMAIL_FROM in the test environment. Verified against vitest.config.mts (sharedTestEnv, lines 23–37) and .env — neither names either variable.

senders.ts reads process.env rather than serverEnv. Every other serverEnv read in src/ sits inside a function. These are module-level constants, so a serverEnv read here would validate the whole server environment at import, in every consumer and every unit spec. ServerEnvSchema still 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. resendAdapter now imports ./brand for the display name. Measured delta at config init: zero — payload.config.ts already imports the @/plugins/email barrel, which already re-exports ./brand, and already imports @/plugins/access, @/plugins/storage and getServerUrl directly. 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

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
@railway-app

railway-app Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-807 environment in sahajcloud

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Sep 18, 2026 at 12:31 am UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-807 September 17, 2026 01:08 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 17, 2026
@sydevs-bot

sydevs-bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 00:20Z address-review · attempt 1 · session · done
  • 00:20Z address-review · attempt 1 · session
  • 01:27Z address-review · attempt 1 · session · done
  • 01:27Z address-review · attempt 1 · session
  • 01:19Z adversarial-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 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 sendEmail site, including the three the diff leaves alone: VerifyEmbeds.ts:130, channels/email.ts:59 and deliverContact.ts:73 all address a manager, so the manager default is right for them.
  • grep -rn CONTACT_EMAIL src/ — no remaining use in a from: position.
  • One 'use client' importer of @/lib/contact (ProjectSelectionPrompt.tsx:6), and it reads CONTACT_EMAIL alone.
  • getEmailBrand().productName is WeMeditate Web, already the auth subject in Managers.ts:43,53.
  • sendEmailStub.ts is unit-lane, distinct from int-lane emailTestAdapter.ts. main carried one local stub, not two.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/lib/contact/index.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 17, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

One thread addressed, rebutted. No commit, nothing pushed — head stays 7382ed1.

Nothing else waits on us. No respondTo login has commented.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Sep 17, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review September 17, 2026 01:31
@sydevs-bot
sydevs-bot requested a review from Ardnived September 17, 2026 01:31
@sydevs-bot sydevs-bot moved this from Revising to Approved in SYDevelopers Technical Roadmap Sep 17, 2026
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Sep 18, 2026
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
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-807 September 18, 2026 00:28 Destroyed
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

One thread addressed, adopted. Pushed 71bd2fc.

Lean gate green — lint, both typechecks, 2133 unit tests — plus event-feedback.int.spec.ts. PR body refreshed: note 1 is now the shipped shape, so the reviewer notes renumber to two.

⚠ 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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Sep 18, 2026
@sydevs-bot
sydevs-bot added this pull request to the merge queue Sep 18, 2026
Merged via the queue into main with commit 43d0b38 Sep 18, 2026
14 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-790-email-sender-split branch September 18, 2026 00:49
@sydevs-bot sydevs-bot moved this from Approved to Done in SYDevelopers Technical Roadmap Sep 18, 2026
Ardnived added a commit that referenced this pull request Sep 25, 2026
…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]>

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-807 — 71bd2fc3 Deployed Sep 18, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(email): Resend drops every email — the sender domain is unverified

3 participants