From e8d7601dcc4d41fb74abecbd2413bf8354129fd1 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:56:43 +0800 Subject: [PATCH] feat(channels): per-user SMTP fields for the Email notification channel (ONE-26) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add smtp_host / smtp_port / smtp_username / smtp_password / smtp_from and from_name to the Email channel form in Channel Management, keeping the frozen notification_configs.email_config contract: - smtp_port stays a string on input and in the PUT body. - smtp_password uses a password input; the API echoes •••••• and the value is submitted back unchanged (or empty) so the backend keeps the old one. - Email field labels/hints are localized through new channels.* keys in zh.json / en.json; other channels keep their existing labels. - Values are trimmed before submitting; the Email card explains that it is independent of Settings → Email Service (system mail untouched). Co-authored-by: multica-agent --- web/src/locales/en.json | 10 ++- web/src/locales/zh.json | 10 ++- web/src/pages/channels/ChannelPage.tsx | 86 +++++++++++++++++++++++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 959c75c..995ff9d 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -369,7 +369,15 @@ "notificationHours": "Notification Hours", "notificationHoursHint": "Notifications are sent at most once per hour. Leave empty to allow every hour.", "notificationHoursClear": "Clear", - "notificationHoursNoLimit": "No restriction" + "notificationHoursNoLimit": "No restriction", + "fromName": "From Name (optional)", + "smtpHost": "SMTP Host", + "smtpPort": "SMTP Port", + "smtpUsername": "SMTP Username", + "smtpPassword": "SMTP Password", + "smtpFrom": "From Address", + "smtpPasswordHint": "Leave empty or keep the placeholder to retain the saved password.", + "emailSmtpHint": "Notification emails are sent through your own SMTP server, independently of the system email settings under Settings → Email Service. Port 465 uses SSL, other ports use STARTTLS." }, "setup": { "title": "Setup", diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 4f43858..49032b9 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -369,7 +369,15 @@ "notificationHours": "通知时段", "notificationHoursHint": "每小时仅发送一次通知。不选则每小时都会发送通知。", "notificationHoursClear": "清空", - "notificationHoursNoLimit": "不限制" + "notificationHoursNoLimit": "不限制", + "fromName": "发件人显示名(可选)", + "smtpHost": "SMTP 主机", + "smtpPort": "SMTP 端口", + "smtpUsername": "SMTP 用户名", + "smtpPassword": "SMTP 密码", + "smtpFrom": "发件地址", + "smtpPasswordHint": "留空或保留占位符即保持已保存的密码不变。", + "emailSmtpHint": "通知邮件通过你自己的 SMTP 服务器发送,与设置页「邮件服务」的系统邮件配置互不影响。端口 465 使用 SSL 加密,其他端口使用 STARTTLS。" }, "setup": { "title": "初始化", diff --git a/web/src/pages/channels/ChannelPage.tsx b/web/src/pages/channels/ChannelPage.tsx index 45ef214..533bd18 100644 --- a/web/src/pages/channels/ChannelPage.tsx +++ b/web/src/pages/channels/ChannelPage.tsx @@ -12,15 +12,25 @@ import type { NotificationConfig } from "@/types"; interface ChannelFieldDef { key: string; + /** Fallback label, used when no i18n key is given. */ label: string; + /** i18n key for the label (e.g. "channels.smtpHost"). */ + labelKey?: string; + /** i18n key for a helper line rendered under the input. */ + hintKey?: string; type: "text" | "password" | "textarea" | "select"; options?: string[]; placeholder?: string; + inputMode?: "text" | "numeric"; + /** Trim surrounding whitespace before submitting (values stay strings). */ + trim?: boolean; } interface ChannelDef { id: string; label: string; + /** i18n key for a helper line rendered above the fields. */ + hintKey?: string; fields: ChannelFieldDef[]; } @@ -84,12 +94,64 @@ const CHANNELS: ChannelDef[] = [ { id: "email", label: "Email", + hintKey: "channels.emailSmtpHint", fields: [ { key: "to", label: "To Address", + labelKey: "channels.toAddress", type: "text", placeholder: "", + trim: true, + }, + { + key: "from_name", + label: "From Name (optional)", + labelKey: "channels.fromName", + type: "text", + trim: true, + }, + { + key: "smtp_host", + label: "SMTP Host", + labelKey: "channels.smtpHost", + type: "text", + placeholder: "smtp.example.com", + trim: true, + }, + { + // Kept as a string end to end: the API contract takes smtp_port as a + // string and converts it to a number when sending. + key: "smtp_port", + label: "SMTP Port", + labelKey: "channels.smtpPort", + type: "text", + placeholder: "465", + inputMode: "numeric", + trim: true, + }, + { + key: "smtp_username", + label: "SMTP Username", + labelKey: "channels.smtpUsername", + type: "text", + placeholder: "user@example.com", + trim: true, + }, + { + key: "smtp_password", + label: "SMTP Password", + labelKey: "channels.smtpPassword", + type: "password", + hintKey: "channels.smtpPasswordHint", + }, + { + key: "smtp_from", + label: "From Address", + labelKey: "channels.smtpFrom", + type: "text", + placeholder: "sender@example.com", + trim: true, }, ], }, @@ -194,6 +256,7 @@ function FormField({ return ( onChange(e.target.value)} className={base} @@ -260,9 +323,16 @@ function ChannelCard({ e.preventDefault(); setSaving(true); setFeedback(null); + const payload: Record = { ...localFields }; + for (const field of channel.fields) { + if (field.trim && typeof payload[field.key] === "string") { + payload[field.key] = payload[field.key].trim(); + } + } try { - await api.put("/me/notifications", { [configKey]: localFields }); - const next: NotificationConfig = { ...config, [configKey]: localFields }; + await api.put("/me/notifications", { [configKey]: payload }); + setLocalFields(payload); + const next: NotificationConfig = { ...config, [configKey]: payload }; onConfigChange(next); setFeedback({ ok: true, msg: t("common.success") }); } catch (err: any) { @@ -326,11 +396,16 @@ function ChannelCard({ {expanded && (
+ {channel.hintKey && ( +

+ {t(channel.hintKey)} +

+ )}
{channel.fields.map((field) => (
({ ...p, [field.key]: v })) } /> + {field.hintKey && ( +

+ {t(field.hintKey)} +

+ )}
))}