Production's SMTP credential has answered "Login denied" since at least
2026-09-05, so every send that "fell back" to it delivered nothing while the
code reported a provider. Mail now goes through Resend (@bitbaum/mail-kit),
or Listmonk when enabled with Resend behind it; a Resend failure is reported
as { success: false } instead of handed to a relay that cannot log in.
Removes transporter.ts, the Brevo probe script, EMAIL_* env, the nodemailer
dependency and its override, and rewrites the email docs to match.
8.2 KiB
Emails & Notifications — SSOT
What gets an email/notification, when, and to whom. Keep this in sync when you add or change any createNotification / notifyUsers / notifyAllStaff / sendCustomEmail call.
Last updated: 2026-07-15.
How it works — two dispatch paths
Path A — Notification system (src/lib/services/notifications.ts)
createNotification(userId, payload, opts?) · notifyUsers(userIds, payload) · notifyAllStaff(payload, excludeUserId?) each write an in-app notification row (the bell) and send an email via trySendEmail to every recipient whose user_profiles.email_notifications !== false (default true).
- Email body:
getEmailContent(payload)uses a dedicated template fordecision_*,it_hilfe_*(whenmetadata.requestUrlset), andcontent_submission_status(whenmetadata.actionset); everything else falls back to the genericnotificationEmail(title, content). opts.skipEmail: true→ in-app row only, no email. Use when a dedicated styled email is already sent for the event via Path B (avoids a second generic email, and still gives a bell entry that survives email-deliverability drops).
Path B — Direct email (sendCustomEmail / sendEmail)
Inline from routes. No in-app row, always a dedicated template. Used by marketplace orders, listing publish/question, appointments, workshops, HR, IT-Hilfe admin alerts.
Central dispatcher for workflow events (timecards, time-off, permissions): src/lib/lifecycle/dispatch.ts.
Recipient resolution helpers: getTimecardApproverIds(excludeUserId?) (staff with timecards/* permission or super-admin), notifyAllStaff, resolveEligibleUserIds (decisions).
Deliverability caveat (READ THIS)
Prod sends via Resend (@bitbaum/mail-kit), from the fleet's verified domain (evig@fleetcrown.orangecat.ch). Before mail-kit it went through Brevo from revampit.ch, which had no SPF/DKIM there, so Brevo accepted mail that consumer mailboxes dropped; that SMTP fallback was removed on 2026-11-10. Still: a provider accepting an email ≠ delivered.
- Most at risk — external recipients: IT-Hilfe requesters + community technicians, marketplace buyers + P2P sellers, job applicants, workshop registrants, service-appointment customers, paying members.
- Lower risk — internal
@revamp-it.ch: all staff-facing notifications (timecards, time-off, decisions, tasks, admin alerts). - Mitigation in code: prefer an in-app notification (Path A, bell) for anything the user must not miss, so it lands regardless of email. Sending from evig's own domain needs that domain verified in Resend first (DNS + DKIM), a separate ops task.
Trigger table
Legend: A = notification system (in-app + maybe email) · B = direct email only · A(skipEmail) = in-app only.
| Event | Path | Recipients | Emails? |
|---|---|---|---|
| Decisions | |||
| Voting opens | A | eligible voters − opener | ✓ |
| Decision closed (manual / cron) | A | creator / all staff | ✓ |
| Voting deadline ~24h | A | non-voters | ✓ |
| Protocols | |||
| Protocol finalized | A | attendees | ✓ (generic) |
| IT-Hilfe | |||
| Request created → requester | A | requester | ✓ |
| Request created → admin alert | B | shared inbox | ✓ |
| Request created → preferred / matching techs | A | preferred + skill-matched active techs | ✓ |
| New offer | A | request owner | ✓ |
| Offer accepted / rejected / declined | A | the helper(s) | ✓ |
| Request completed / review received | A | requester / reviewed helper | ✓ |
| Marketplace | |||
| Order placed → buyer | B | buyer | ✓ |
| Order placed → seller | B + A(skipEmail) | seller (styled email + bell entry) | ✓ |
| Cart paid (webhook) | B | buyer + seller | ✓ |
| Listing published | B | seller | ✓ |
| Question / receipt-confirmed / review | A + B | seller (⚠ double email, see follow-ups) | ✓✓ |
| Membership | |||
| Payment recorded | A | the member | ✓ (generic) |
| Workshops | |||
| Free registration | B + A | registrant (email) + all staff (in-app) | ✓ |
| Proposal approved | A | proposer | ✓ |
| Service appointments | |||
| Booking → admins | A + B | all staff + shared inbox (if unassigned) | ✓ |
| Booking → assigned repairer | A | the repairer | ✓ |
| Booking → customer | A | the customer (in-app + generic email) | ✓ |
| Quote/accept/reject/start/complete | B | customer / repairer | ✓ |
| Completed → staff | A | all staff − actor | ✓ |
| Timecards | |||
| Submitted → other approvers | A | approvers − submitter | ✓ |
| Submitted → submitter | A (timecard_submit_confirmed) |
the submitter (also "you can approve it yourself" when sole approver) | ✓ |
| Approved / rejected / reopened / edited | A | card owner | ✓ |
| Time-off | |||
| Submitted → approvers | A | approvers | ✓ |
| Reviewed → requester | A | requester | ✓ |
| Permissions | |||
| Access requested / reviewed | A | super admins / requester | ✓ |
| HR | |||
| Application → staff / applicant | A + B | all staff (in-app) + applicant (email) | ✓ |
| Status changed | A/B | applicant | ✓ |
| Blog | |||
| Status change | A + B | submitter | ✓ |
| Tasks | |||
| Assigned / requested / completed / accepted / recurring | A | assignee / requester / creator / staff | ✓ |
| Teams | |||
| Invited by email (new person / placeholder) | B (teamClaimInvite) |
the invitee's real address (claim link, 14d) | ✓ |
| Added to a team by an admin | B (teamMemberAdded) |
the added member (self-join stays silent) | ✓ |
Fixed 2026-07-09 (commit trail in git)
- Timecard submitted → submitter now gets a confirmation (
timecard_submit_confirmed), and when the submitter is the sole approver it also tells them they can approve it themselves. Previously the submitter got nothing, and a sole-super-admin approver submitting their own card notified nobody (getTimecardApproverIdsexcludes the submitter). —src/lib/services/timecards.ts - Order placed → seller now gets an in-app bell entry (
listing_sold,skipEmailso no duplicate of the styled email). Robust against email drops. NewRELATED_TYPES.ORDER→/dashboard/orders/. —src/app/api/marketplace/orders/route.ts - Service booking → customer now acknowledged (in-app + generic email) at booking time. Previously only admins + the assigned repairer were notified. —
src/app/api/appointments/route.ts createNotificationgainedopts.skipEmailfor in-app-only notifications.
Known follow-ups (NOT yet done)
- Paid workshop registration (webhook) sends no confirmation —
src/lib/services/payment-webhook.ts:451only logs. Fix: sendworkshopRegistrationConfirmationon payment success. (Deferred: the Payrexx-paid path isn't live/testable yet.) - Paid service appointment (webhook) sends no confirmation —
payment-webhook.ts:457only logs. Same deferral. - ✅ DONE — Marketplace double emails fixed: the seller
createNotificationin the question (listings/[id]/questions), confirm-receipt and review routes now pass{ skipEmail: true }, so only the dedicated styled email is sent (the bell entry stays). - ✅ DONE — Time-off requester acknowledgement added:
createTimeOffRequestnow sends the requester an in-apptime_off_requestedconfirmation (→/admin/zeiterfassung) at submit time, mirroring the timecard-submit confirmation. - ✅ DONE — SSOT drift fixed: added
NOTIFICATION_TYPES.TASK_ASSIGNEDand both task routes use the constant (the stalenotifications_type_checkDB constraint note in the config was also corrected — it was dropped in migration 110). - ✅ DONE — Dead notification types pruned: removed
message,vacancy_published,marketing,task_broadcastfromNOTIFICATION_TYPES(verified zero producers — nocreateNotification/notifyUsersemits them, and they appear in no label/icon/href map). Keptappointment/marketplace/system(all have producers). - Deliverability: mail leaves from the shared verified fleet domain. Sending from evig's own domain needs it registered and verified in Resend first.