Skip to content

app/: transactional emails: outbox, Postmark, member notices (sc-8900) - #60

Merged
ndbroadbent merged 4 commits into
mainfrom
laravel-emails
Dec 2, 2026
Merged

ndbroadbent merged 4 commits into
mainfrom
laravel-emails

Conversation

@ndbroadbent

Copy link
Copy Markdown
Member

Stacked on #56. Today's transactional emails, ported to the Laravel Rust app.

  • What they say: every Kind and render (subject, text and HTML) carried across from server/src/notify.rs unchanged, with today's samples.
  • The outbox: emails, the same table as today, including dismissed_at.
    • notify::queue(kind, To::{User, Billing, Admins}, org, dedupe_key) records an email once per dedupe key and recipient.
    • It goes to the billing email or else the admins, and only those who haven't turned low-credit warnings or receipts off (users.email_low_credits and email_receipts, added here with signup_notified_at).
  • Delivery:
    • DeliverEmails claims up to 50 pending emails (FOR UPDATE SKIP LOCKED) and sends each through Postmark (POSTMARK_SERVER_TOKEN, MAIL_FROM, MAIL_REPLY_TO) with Laravel's HTTP client.
    • A failed send stays pending, and after five attempts it's marked failed.
    • The job is queued whenever an email is, and scheduled every five minutes for anything left over.
    • oldest_unsent_seconds() is there for /status, which is the job's health check, as today.
  • Member notices: a MembershipChanged listener sends the added-to or removed-from-organization email.
  • billing::CREDIT_PACK moves over with the emails that quote it. The rest of billing follows.

Tests (app/tests/emails.rs, Postmark faked):

  • every email renders;
  • the outbox queues once per period, skips an admin who turned the email off, and sends;
  • a failed send stays pending with its attempt and error.

All app tests pass, and clippy is clean.

@ndbroadbent

Copy link
Copy Markdown
Member Author

Added, per AGENTS.md:

  • A heartbeat that checks the work. After each run, DeliverEmails pushes VISUALCI_EMAILS_HEARTBEAT_URL (a Gatus external endpoint, with VISUALCI_EMAILS_HEARTBEAT_TOKEN), ported from today's heartbeat.rs. It fails when delivery errored or the oldest unsent email has waited over 30 minutes, so a job that runs but stops sending still alerts. The Gatus endpoint itself goes in at cutover with the other heartbeats.
  • /status: failed_unresolved_count() (today's emails_failed_unresolved) and oldest_unsent_seconds(), ready for the status route.

@visualci-com

visualci-com Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

VisualCI

docspring/visualci · build #321 · 331 unchanged · no changes

This PR vs base: nothing since #213, across 6 builds

Updated as builds change. Agents can review with VisualCI's MCP tools.

@ndbroadbent
ndbroadbent force-pushed the laravel-emails branch 2 times, most recently from 8314f0c to 157198b Compare December 2, 2026 14:00
@ndbroadbent
ndbroadbent force-pushed the laravel-emails branch 2 times, most recently from 1fd39a2 to 1bfecb7 Compare December 2, 2026 15:28
@ndbroadbent
ndbroadbent changed the base branch from laravel-memberships to main December 2, 2026 16:06
…orted as is, the emails outbox (once per dedupe key and recipient; billing email or admins with their choices), DeliverEmails through Postmark (queued on each email, scheduled every five minutes; five attempts, then failed), a member's notice on MembershipChanged; emails table and users' email choices
…UALCI_EMAILS_HEARTBEAT_URL/TOKEN; fails when the oldest unsent email has waited over 30 minutes or delivery errored), and failed_unresolved_count for /status (emails_failed_unresolved, as today)
…claim lapses after 30 minutes, far longer than a 10-second send), so a slow run's batch is never sent twice; a crashed run's fifth attempt ends failed, never a sixth; a failed send waits five minutes for the next run; the membership notice's dedupe key is the change's time, fixed at dispatch, so a retried listener doesn't send it again
@ndbroadbent
ndbroadbent merged commit add224f into main Dec 2, 2026
11 checks passed
@ndbroadbent
ndbroadbent deleted the laravel-emails branch December 2, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant