# 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** for `decision_*`, `it_hilfe_*` (when `metadata.requestUrl` set), and `content_submission_status` (when `metadata.action` set); **everything else falls back to the generic `notificationEmail(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** (`getTimecardApproverIds` excludes the submitter). — `src/lib/services/timecards.ts` - **Order placed → seller now gets an in-app bell entry** (`listing_sold`, `skipEmail` so no duplicate of the styled email). Robust against email drops. New `RELATED_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` - **`createNotification` gained `opts.skipEmail`** for in-app-only notifications. ## Known follow-ups (NOT yet done) 1. **Paid workshop registration (webhook) sends no confirmation** — `src/lib/services/payment-webhook.ts:451` only logs. Fix: send `workshopRegistrationConfirmation` on payment success. *(Deferred: the Payrexx-paid path isn't live/testable yet.)* 2. **Paid service appointment (webhook) sends no confirmation** — `payment-webhook.ts:457` only logs. Same deferral. 3. ✅ **DONE** — **Marketplace double emails** fixed: the seller `createNotification` in 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). 4. ✅ **DONE** — **Time-off requester acknowledgement** added: `createTimeOffRequest` now sends the requester an in-app `time_off_requested` confirmation (→ `/admin/zeiterfassung`) at submit time, mirroring the timecard-submit confirmation. 5. ✅ **DONE** — **SSOT drift** fixed: added `NOTIFICATION_TYPES.TASK_ASSIGNED` and both task routes use the constant (the stale `notifications_type_check` DB constraint note in the config was also corrected — it was dropped in migration 110). 6. ✅ **DONE** — **Dead notification types pruned:** removed `message`, `vacancy_published`, `marketing`, `task_broadcast` from `NOTIFICATION_TYPES` (verified zero producers — no `createNotification`/`notifyUsers` emits them, and they appear in no label/icon/href map). Kept `appointment`/`marketplace`/`system` (all have producers). 7. **Deliverability:** mail leaves from the shared verified fleet domain. Sending from evig's own domain needs it registered and verified in Resend first.