stalwartlabs / mail-send

E-mail delivery library for Rust with DKIM support
https://docs.rs/mail-send/
Apache License 2.0
210 stars 21 forks source link

Elastic template #32

Closed Cheban1996 closed 8 months ago

Cheban1996 commented 8 months ago

I want to send a message containing an email in a template, but I don't want to call SmtpClient Builder::new every time for each email. Maybe you know how to make it more elastic?

let template = format!("Dear {email}, You are now change your email.");
let emails = vec![...];
let message = MessageBuilder::new()
            .from((username, email))
            .to(emails)
            .subject("Subject")
            .text_body(&template);

 SmtpClientBuilder::new(self.hostname.clone(), self.port)
            .implicit_tls(false)
            .credentials((self.from.clone(), self.password.clone()))
            .connect()
            .await
            .expect("connect to send email")
            .send(message)
            .await
            .unwrap();

As a solution maybe need implement .send_many(message) where we can create message for every individual user?

mdecimus commented 8 months ago

You can create just one SmtpClient and use it to send multiple messages. There is no need to create a new client for each message you need to send.