Skip to content

ONE-21: Email 通知渠道每用户 SMTP 实现 - #133

Closed
mapxn wants to merge 1 commit into
mainfrom
agent/daniel/9b9e13d71665
Closed

mapxn wants to merge 1 commit into
mainfrom
agent/daniel/9b9e13d71665

Conversation

@mapxn

@mapxn mapxn commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

变更

Email 通知渠道改为使用每用户自配 SMTP(notification_configs.email_config),不再复用全局系统邮件的 sendEmail()。

  • worker/src/services/email.ts:把 SMTP 发送逻辑抽成可复用函数 sendSmtpMail(config: SMTPConfig, options: EmailOptions);系统邮件 sendViaSMTP 改为调用它,行为不变。导出 SMTPConfig / EmailOptions / isValidEmail。
  • worker/src/services/notify/email-notify.ts:读取 smtp_host / smtp_port / smtp_username / smtp_password / smtp_from,用 sendSmtpMail 发送;smtp_host 为空时返回 Email channel SMTP not configured,不回落系统邮件;发件人取 smtp_from || smtp_username;端口 465 = 隐式 TLS,其余 STARTTLS(沿用原逻辑)。
  • worker/test/email-notify.test.ts:新增 8 条单测(配置校验、字段映射、SMTP 错误透传)。

系统/安全邮件路径(routes/auth.ts、services/twofa.ts、routes/admin.ts)未改动。

自测

  • pnpm typecheck 通过(web tsc -b + worker tsc --noEmit)
  • pnpm test 通过:7 个测试文件 / 62 条测试(其中本单新增 8 条)

Split notification mail from system mail: the Email notification channel now
sends through each user's own `notification_configs.email_config` SMTP
account instead of the global `sendEmail()` settings.

- email.ts: extract the SMTP send path into a reusable `sendSmtpMail(config,
  options)`; `sendViaSMTP` (system mail) now delegates to it, unchanged
  behavior. Export `SMTPConfig` / `EmailOptions` / `isValidEmail`.
- email-notify.ts: read `smtp_host` / `smtp_port` / `smtp_username` /
  `smtp_password` / `smtp_from`, send via `sendSmtpMail`; empty `smtp_host`
  returns "Email channel SMTP not configured" with no system-mail fallback;
  sender is `smtp_from || smtp_username`; port 465 = implicit TLS, otherwise
  STARTTLS (same logic as before).
- test/email-notify.test.ts: cover config validation, field mapping and
  SMTP error relay.
@mapxn

mapxn commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

按用户拍板(ONE-25 评论「用 135」),本 PR 由 #135 取代,关闭不再合并。

同一范围的实现保留在:#135(ONE-25,分支 feat/ONE-25-per-user-smtp),其中包含本 PR 的全部契约行为(错误文案 / / 已对齐),另加真实假 SMTP 服务器的端到端测试与 me.ts 密码脱敏往返测试。对应的 ONE-21 单由 Mike 按重复单收口。

@mapxn mapxn closed this Oct 22, 2026
@mapxn

mapxn commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

按用户拍板(ONE-25 评论「用 135」),本 PR 关闭、不再合并。

同一范围的实现保留在 #135(ONE-25,分支 feat/ONE-25-per-user-smtp):契约行为与错误文案 Email channel SMTP not configured / Invalid Email channel SMTP port / Invalid Email channel SMTP sender (set smtp_from or smtp_username) 均已对齐,另补了真实假 SMTP 服务器的端到端测试与 me.ts 密码脱敏往返测试。

(上一条自动关闭评论因 shell 展开了反引号导致文案残缺,以此条为准。)ONE-21 单由 Mike 按重复单收口。

@mapxn
mapxn deleted the agent/daniel/9b9e13d71665 branch November 8, 2026 11:28
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