From af8f24aa956f8230f664abc8910802179cfad9d8 Mon Sep 17 00:00:00 2001 From: Yiling-J Date: Mon, 28 Sep 2026 11:27:59 +0800 Subject: [PATCH] docs(settings): add email notifications documentation to team settings (#432) * docs(settings): add email notification documentation to team settings * fix(notification): use correct webui route URLs for project and asset links in emails --- CHANGELOG.md | 7 +- docs/configuration/env-variables.mdx | 11 +- docs/docs.json | 1 + docs/using-shumai/email-notifications.mdx | 127 +++++++++++++++++++ docs/using-shumai/notifications.mdx | 8 ++ packages/core/src/notification/email.test.ts | 94 ++++++++++++++ packages/core/src/notification/email.ts | 70 +++++----- 7 files changed, 269 insertions(+), 49 deletions(-) create mode 100644 docs/using-shumai/email-notifications.mdx diff --git a/CHANGELOG.md b/CHANGELOG.md index 138e2440..556e235f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,17 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added -- **notification**: Add periodic background job that batches notifications into single digest emails per user, with smart collapsing for high-volume events, user preference filtering, and presigned thumbnails -- **webui**: Add team email notification settings page with SMTP configuration and test email dialog -- **notification**: Add email notification infrastructure with team-level SMTP configuration, test email delivery, and rich HTML templates +- **notification**: You can now receive notifications via email, with batched digest emails and configurable team-level SMTP settings - **transcode**: Add VA-API hardware acceleration support for Linux hosts and Docker environments with Intel and AMD GPUs, featuring automatic DRI render node discovery, variable bitrate control, and structured transcoding observability logs - **docker**: Add modular hardware-accelerated transcoding presets matching Immich's compose configuration via `hwaccel.transcoding.yaml` with support for NVENC, QuickSync, RKMPP, and VA-API ### Fixed -- **notification**: Embed avatars and asset thumbnails as inline CID attachments in notification digest emails for reliable image display across email providers without external link blocking -- **team**: Prevent email notification configuration and SMTP credentials from being exposed through general team settings - ### Changed - **transcode**: Improve video poster selection using intelligent scene detection and color variance filtering to automatically skip black frames, fade-ins, and blank intros in favor of representative video content diff --git a/docs/configuration/env-variables.mdx b/docs/configuration/env-variables.mdx index 3f20e3c2..8efe93e2 100644 --- a/docs/configuration/env-variables.mdx +++ b/docs/configuration/env-variables.mdx @@ -24,12 +24,13 @@ Shumai is configured via environment variables. You can define these variables i --- -## Authentication Config +## Authentication & Application Config -| Variable | Description | Example / Default | -| :------------------- | :--------------------------------------------------------------------- | :--------------------------------------------------------------- | -| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` | -| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) | +| Variable | Description | Example / Default | +| :------------------- | :--------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------- | +| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` | +| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows and notification email links fallback. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) | +| `APP_URL` | The public URL of the web application. Used for notification email deep links (falls back to `BETTER_AUTH_URL`). | `https://shumai.example.com` | --- diff --git a/docs/docs.json b/docs/docs.json index 4cf129e9..4b696218 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -65,6 +65,7 @@ "pages": [ "using-shumai/transcode-settings", "using-shumai/quotas-settings", + "using-shumai/email-notifications", "using-shumai/password-reset" ] }, diff --git a/docs/using-shumai/email-notifications.mdx b/docs/using-shumai/email-notifications.mdx new file mode 100644 index 00000000..f97fcce4 --- /dev/null +++ b/docs/using-shumai/email-notifications.mdx @@ -0,0 +1,127 @@ +--- +title: Email Notifications +description: Configure team SMTP settings, deliver batched activity digest emails, and send test emails. +--- + +Shumai includes a built-in email notification system that delivers updates on team activities—such as comments, mentions, new asset uploads, status changes, and Kanban tasks—directly to team members' inboxes. + +To prevent inbox clutter and notification fatigue, Shumai does not send emails for every single action individually. Instead, a background delivery service aggregates pending notifications and sends periodic, batched digest emails with inline thumbnails and deep links. + +--- + +## Configuring SMTP Settings + +Email notification settings are managed at the team level by **Team Owners**. + +To configure outgoing mail: + +1. Click on **Team Settings** in the sidebar. +2. Select the **Email Notifications** tab. +3. Turn on the **Enable Email Notifications** switch. +4. Fill in your SMTP server credentials and sender information. +5. Click **Save** or **Save and Send Test Email**. + +### SMTP Server Settings + +| Field | Description | Example / Default | +| :---------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------- | +| **SMTP Host** | The hostname or IP address of your outgoing SMTP server. | `smtp.example.com` or `smtp.sendgrid.net` | +| **SMTP Port** | The port used to connect to your SMTP server. | `587` (default, STARTTLS), `465` (SSL/TLS), or `25` | +| **Username** | The username or API key required to authenticate with the SMTP server. | `user@example.com` or `apikey` | +| **Password** | The authentication password or API secret. | `••••••••` | +| **SSL / TLS (SMTPS)** | Connect directly using SSL/TLS encryption. Typically required when connecting over port `465`. | `Disabled` (default) | +| **Ignore Certificate Errors** | Allows connections with self-signed, invalid, or unverified TLS certificates. Useful for local testing (e.g. Mailpit, MailHog) or private corporate relays. | `Disabled` (default) | + +> [!TIP] +> **Password Retention**: When updating existing email settings, you can leave the password input blank to keep the currently stored password. For security, stored passwords are never returned in cleartext to the client. + +### Sender Information + +| Field | Description | Example / Default | +| :----------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------- | +| **From** | The sender name and email address that will appear in the `From` header. Ensure your SMTP provider is authorized to send on behalf of this address. | `Shumai ` | +| **Reply-To** | _(Optional)_ An email address to receive replies if members respond directly to a notification email. | `support@example.com` | + +--- + +## Testing SMTP Delivery + +Before relying on email delivery, you can verify your configuration and credentials directly from the settings page: + +1. Click **Save and Send Test Email**. +2. In the **Send Test Email** modal, verify or adjust the sender `From` address. +3. Click **Send Test Email**. + +Shumai will perform an active handshake verification (`transport.verify()`) against your SMTP server and dispatch a styled test message to the email address of the currently logged-in administrator. + +If the handshake or delivery fails (for example, due to an invalid password, blocked outbound port, or rejected sender address), an error toast is displayed with the exact message returned by the SMTP server. + +--- + +## Delivery Architecture & Digest Batching + +Shumai uses an asynchronous, batched architecture for email delivery: + +``` +[ Team Activity ] +(Comments, Uploads, Mentions, Kanban) + │ + ▼ +[ Database Queue ] (status: pending) + │ + ▼ (Every 3 minutes) +[ Notification Background Job ] + │ + ├─ Filter recipients (check user preferences & project scope) + ├─ Exclude self-actions and AI agents + ├─ Group & collapse items (clusters > 3 summarized) + ├─ Fetch avatars & thumbnails as inline CID attachments + │ + ▼ +[ Nodemailer Transport ] ──> SMTP Server ──> [ Member Inboxes ] +``` + +### 1. Periodic Background Delivery + +Notifications are queued in PostgreSQL with a `pending` status. A background job runs periodically every **3 minutes**, acquiring pending notifications using atomic queue locking (`FOR UPDATE SKIP LOCKED`). This ensures safe delivery without duplicate emails even when multiple server instances run concurrently. + +### 2. Digest Bundling + +Rather than sending an email immediately for each action, all notifications collected for a recipient during the 3-minute window are combined into a single digest email. This keeps team communication organized and eliminates inbox spam during heavy collaboration sessions. + +### 3. Smart Activity Collapsing + +When an event cluster contains a high volume of items (for example, when an editor uploads dozens of video clips at once), Shumai automatically groups and collapses the items: + +- If **3 or fewer** items are in a group, each item is displayed with its individual thumbnail and details. +- If **more than 3** items are uploaded together, Shumai summarizes them into a single concise notification (e.g., _"Alice uploaded 12 new files to Project Alpha"_) with a preview of the first three file names. + +### 4. Inline CID Attachments + +Avatars and video/image asset thumbnails are retrieved from storage and embedded directly into the email as inline MIME attachments (`cid:...`). + +Unlike external image links, inline CID attachments: + +- Display immediately in desktop and mobile email clients (such as Apple Mail, Gmail, and Outlook) without being blocked by "show remote content" security warnings. +- Do not require publicly accessible S3 URLs or reverse-proxy authentication to render. + +### 5. Deep Linking + +Every notification card in the email includes deep-linking action buttons (such as **View Asset**, **View Project**, or **View Task**) that navigate members straight to the corresponding resource in Shumai. + +To ensure links point to your public domain instead of `localhost`, configure the `APP_URL` or `BETTER_AUTH_URL` environment variable on your Shumai server: + +```bash +APP_URL=https://shumai.example.com +``` + +--- + +## Member Preferences & Filtering + +Email delivery respects team permissions and member choices: + +- **Personal Preferences**: Team members can independently choose which types of activities they receive by opening **Team Settings > Notifications**. If a user disables notifications for a category (e.g. general comments or status updates), Shumai will not include those items in their email digests. +- **Self-Action Suppression**: Members never receive notification emails for their own comments, uploads, or task updates (unless they explicitly enable the **Your Uploads** preference to be notified when their own media transcoding completes). +- **Project Scope**: Members whose access is restricted to specific projects only receive email digests for activities within those assigned projects, unless they are explicitly `@mentioned`. +- **AI Agents**: Automated AI agent accounts are automatically excluded from receiving email notifications. diff --git a/docs/using-shumai/notifications.mdx b/docs/using-shumai/notifications.mdx index f57bdc76..6b542447 100644 --- a/docs/using-shumai/notifications.mdx +++ b/docs/using-shumai/notifications.mdx @@ -44,3 +44,11 @@ If you want to mute a specific project entirely (except for direct `@mentions` w - The **Bell** icon in the navigation bar displays a red badge when you have unread notifications. - Click the bell to open your notification feed panel. - Click any notification card to mark it as read and jump directly to the relevant file and comment thread. + +--- + +## Email Notifications + +In addition to in-app notifications, Team Owners can configure outgoing SMTP settings to deliver batched activity digest emails to team members. The email delivery engine honors each member's individual notification preferences configured above. + +See the [Email Notifications Guide](/using-shumai/email-notifications) for full SMTP setup instructions, test email workflows, and delivery architecture details. diff --git a/packages/core/src/notification/email.test.ts b/packages/core/src/notification/email.test.ts index 18d4b8f6..7f29d2ba 100644 --- a/packages/core/src/notification/email.test.ts +++ b/packages/core/src/notification/email.test.ts @@ -441,6 +441,41 @@ describe('EmailService', () => { expect(status.subject).toContain('Grace updated status of task "Refactor auth"') expect(status.html).toContain('Moved to In Progress') }) + + it('generates correct action links without team id for project and asset URLs', () => { + const baseUrl = emailService.getBaseUrl() + + // Project link + const projectEmail = emailService.renderNotificationEmail({ + type: NotificationType.new_user_join_project, + creatorName: 'Alice', + teamName: 'Designers', + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + projectName: 'Project Alpha', + projectId: '01KY2ANCA1SXGSPR63NVVD07EJ', + }) + expect(projectEmail.html).toContain(`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`) + expect(projectEmail.html).not.toContain( + '/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ', + ) + + // Asset link + const assetEmail = emailService.renderNotificationEmail({ + type: NotificationType.comment_created, + creatorName: 'Alice', + teamName: 'Designers', + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + projectName: 'Project Alpha', + projectId: '01KY2ANCA1SXGSPR63NVVD07EJ', + assetId: '01KY2ASSET1234567890ABCDEF', + assetName: 'logo.png', + commentMessage: 'Looks good', + }) + expect(assetEmail.html).toContain( + `href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`, + ) + expect(assetEmail.html).not.toContain('/teams/') + }) }) describe('renderBatchedNotificationEmail', () => { @@ -594,5 +629,64 @@ describe('EmailService', () => { expect(rendered.html).toContain('diagram.png') expect(rendered.html).toContain('https://example.com/diagram.png') }) + + it('generates correct project action links in batched notification emails', () => { + const baseUrl = emailService.getBaseUrl() + + const rendered = emailService.renderBatchedNotificationEmail({ + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + teamName: 'Designers', + recipientName: 'Bob', + items: [ + { + id: 'n-1', + type: NotificationType.successful_file_uploaded, + creatorName: 'Alice', + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + teamName: 'Designers', + projectId: '01KY2ANCA1SXGSPR63NVVD07EJ', + projectName: 'Project Alpha', + assetId: '01KY2ASSET1234567890ABCDEF', + assetName: 'hero.png', + createdAt: new Date('2026-09-27T10:00:00Z'), + }, + ], + }) + + expect(rendered.html).toContain( + `href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`, + ) + expect(rendered.html).not.toContain( + '/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ', + ) + + // Test collapsed group (>3 items) + const collapsedItems = Array.from({ length: 4 }, (_, i) => ({ + id: `n-${i}`, + type: NotificationType.successful_file_uploaded, + creatorName: 'Alice', + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + teamName: 'Designers', + projectId: '01KY2ANCA1SXGSPR63NVVD07EJ', + projectName: 'Project Alpha', + assetId: `asset-${i}`, + assetName: `file_${i}.png`, + createdAt: new Date('2026-09-27T10:00:00Z'), + })) + + const renderedCollapsed = emailService.renderBatchedNotificationEmail({ + teamId: '01KY2A7DRK2N0MECBDHTGAVV84', + teamName: 'Designers', + recipientName: 'Bob', + items: collapsedItems, + }) + + expect(renderedCollapsed.html).toContain( + `href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`, + ) + expect(renderedCollapsed.html).not.toContain( + '/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ', + ) + }) }) }) diff --git a/packages/core/src/notification/email.ts b/packages/core/src/notification/email.ts index 2724e815..b91359f2 100644 --- a/packages/core/src/notification/email.ts +++ b/packages/core/src/notification/email.ts @@ -312,20 +312,18 @@ Sent from Shumai at ${baseUrl} let actionUrl = baseUrl let actionText = 'View in Shumai' - if (ctx.teamId) { - if (ctx.projectId && ctx.assetId) { - actionUrl = `${baseUrl}/teams/${ctx.teamId}/projects/${ctx.projectId}?assetId=${ctx.assetId}` - actionText = 'View Asset' - } else if (ctx.projectId) { - actionUrl = `${baseUrl}/teams/${ctx.teamId}/projects/${ctx.projectId}` - actionText = 'View Project' - } else if (ctx.kanbanTaskId) { - actionUrl = `${baseUrl}/teams/${ctx.teamId}?kanbanTaskId=${ctx.kanbanTaskId}` - actionText = 'View Task' - } else { - actionUrl = `${baseUrl}/teams/${ctx.teamId}` - actionText = 'Open Team' - } + if (ctx.projectId && ctx.assetId) { + actionUrl = `${baseUrl}/projects/${ctx.projectId}/files/${ctx.assetId}` + actionText = 'View Asset' + } else if (ctx.projectId) { + actionUrl = `${baseUrl}/projects/${ctx.projectId}` + actionText = 'View Project' + } else if (ctx.teamId && ctx.kanbanTaskId) { + actionUrl = `${baseUrl}/teams/${ctx.teamId}/kanban?taskId=${ctx.kanbanTaskId}` + actionText = 'View Task' + } else if (ctx.teamId) { + actionUrl = `${baseUrl}/teams/${ctx.teamId}` + actionText = 'Open Team' } let subject = '[Shumai] Notification' @@ -673,9 +671,7 @@ Team: ${ctx.teamName} return t > latest ? t : latest }, 0) const timeStr = latestTime > 0 ? formatUploadTime(new Date(latestTime)) : undefined - const targetUrl = first.projectId - ? `${baseUrl}/teams/${ctx.teamId}/projects/${first.projectId}` - : teamUrl + const targetUrl = first.projectId ? `${baseUrl}/projects/${first.projectId}` : teamUrl htmlRows.push( ` @@ -840,27 +836,25 @@ function getItemAction( baseUrl: string, item: BatchedNotificationItem, ): { url: string; text: string } { - if (item.teamId) { - if (item.projectId && item.assetId) { - return { - url: `${baseUrl}/teams/${item.teamId}/projects/${item.projectId}?assetId=${item.assetId}`, - text: 'View Asset', - } - } else if (item.projectId) { - return { - url: `${baseUrl}/teams/${item.teamId}/projects/${item.projectId}`, - text: 'View Project', - } - } else if (item.kanbanTaskId) { - return { - url: `${baseUrl}/teams/${item.teamId}?kanbanTaskId=${item.kanbanTaskId}`, - text: 'View Task', - } - } else { - return { - url: `${baseUrl}/teams/${item.teamId}`, - text: 'Open Team', - } + if (item.projectId && item.assetId) { + return { + url: `${baseUrl}/projects/${item.projectId}/files/${item.assetId}`, + text: 'View Asset', + } + } else if (item.projectId) { + return { + url: `${baseUrl}/projects/${item.projectId}`, + text: 'View Project', + } + } else if (item.teamId && item.kanbanTaskId) { + return { + url: `${baseUrl}/teams/${item.teamId}/kanban?taskId=${item.kanbanTaskId}`, + text: 'View Task', + } + } else if (item.teamId) { + return { + url: `${baseUrl}/teams/${item.teamId}`, + text: 'Open Team', } } return { url: baseUrl, text: 'Open Shumai' }