From 6800efe2b16270a8bea57d5c4676d141b65f6679 Mon Sep 17 00:00:00 2001 From: iDoge Date: Mon, 18 Mar 2024 21:44:32 +0800 Subject: [PATCH] feat: support multi recipients --- server/src/notifier/email.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/notifier/email.rs b/server/src/notifier/email.rs index bf71432e..57e17cea 100644 --- a/server/src/notifier/email.rs +++ b/server/src/notifier/email.rs @@ -1,7 +1,7 @@ #![deny(warnings)] use anyhow::Result; use lettre::{ - message::{header, MultiPart, SinglePart}, + message::{header, Mailboxes, MultiPart, SinglePart}, transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, }; @@ -48,10 +48,16 @@ impl crate::notifier::Notifier for Email { } fn send_notify(&self, html_content: String) -> Result<()> { - let email = Message::builder() - .from(format!("ServerStatus <{}>", self.config.username).parse().unwrap()) - .to(self.config.to.parse().unwrap()) + let mut builder = Message::builder() .subject(self.config.subject.to_string()) + .from(format!("ServerStatus <{}>", self.config.username).parse().unwrap()); + + let mailboxes: Mailboxes = self.config.to.parse().expect("Invalid email addresses"); + for mailbox in mailboxes.iter() { + builder = builder.to(mailbox.clone()); + } + + let email = builder .multipart( MultiPart::alternative().singlepart( SinglePart::builder()