From ff718d7cd2102ce6b589274462377bd7ad5efcc2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Jul 2026 14:54:37 +0000 Subject: [PATCH 1/2] Initial plan From b3cc57f91cb6c61edb03382f9a3d927daceaad5b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 11 Jul 2026 15:00:51 +0000 Subject: [PATCH 2/2] fix: address review comments on email notifier from field - Add `from: Option` to email Config struct - Treat empty/whitespace `from` as unconfigured, falling back to `username` - Replace `.unwrap()` with `?` on mailbox parse to propagate errors via Result - Update config.toml comment: clarify field must be absent (not empty) to use username fallback --- config.toml | 4 ++++ server/src/notifier/email.rs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.toml b/config.toml index da4cfb55..31b5529d 100644 --- a/config.toml +++ b/config.toml @@ -117,6 +117,10 @@ custom_tpl = """ [email] enabled = false server = "smtp.gmail.com" +# 可选:发件人邮箱地址。 +# 部分服务商(如 SendGrid)SMTP 登录账号(username)为 API Key 而非邮箱地址, +# 此时需在此填写真实发件邮箱;未配置该字段则默认使用 username 作为发件地址。 +#from = "user@email.com" username = "user@email.com" password = "***" to = "user1@email.com;user2@email.com" diff --git a/server/src/notifier/email.rs b/server/src/notifier/email.rs index a6bbcb71..fc826500 100644 --- a/server/src/notifier/email.rs +++ b/server/src/notifier/email.rs @@ -20,6 +20,7 @@ pub struct Config { pub server: String, pub username: String, pub password: String, + pub from: Option, pub to: String, pub subject: String, pub title: String, @@ -48,9 +49,16 @@ impl crate::notifier::Notifier for Email { } fn send_notify(&self, html_content: String) -> Result<()> { + let from_addr = self + .config + .from + .as_deref() + .map(str::trim) + .filter(|s| !s.is_empty()) + .unwrap_or(&self.config.username); let mut builder = Message::builder() .subject(self.config.subject.clone()) - .from(format!("ServerStatus <{}>", self.config.username).parse().unwrap()); + .from(format!("ServerStatus <{from_addr}>").parse()?); let mailboxes: Mailboxes = self.config.to.parse().expect("Invalid email addresses"); for mailbox in mailboxes.iter() {