Files
piperun-bot/src/send_mail_util.rs

47 lines
1.6 KiB
Rust

pub mod send_mail_util {
use lettre::{
Message, SmtpTransport, Transport,
message::{self, Attachment, Mailboxes, MultiPart, SinglePart, header::ContentType},
};
pub fn send_email(
subject_of_email: &str,
bot_email: &str,
bot_email_password: &str,
to: &str,
zip_file_name: &str,
) {
let filebody = std::fs::read(zip_file_name).unwrap();
let content_type = ContentType::parse("application/zip").unwrap();
let attachment = Attachment::new(zip_file_name.to_string()).body(filebody, content_type);
let mailboxes: Mailboxes = to.parse().unwrap();
let to_header: message::header::To = mailboxes.into();
let email = Message::builder()
.from(format!("PipeRUN bot <{bot_email}>").parse().unwrap())
.reply_to(format!("PipeRUN bot <{bot_email}>").parse().unwrap())
.mailbox(to_header)
.subject(format!("{subject_of_email}"))
.multipart(
MultiPart::mixed()
.singlepart(
SinglePart::builder()
.header(ContentType::TEXT_PLAIN)
.body(String::from("Avaliacao dos atendimentos")),
)
.singlepart(attachment),
)
.unwrap();
// Create the SMTPS transport
let sender = SmtpTransport::from_url(&format!(
"smtps://{bot_email}:{bot_email_password}@mail.nova.net.br"
))
.unwrap()
.build();
// Send the email via remote relay
sender.send(&email).unwrap();
}
}