feat: send result to multiple email addresses

This commit is contained in:
2025-10-02 10:58:12 -03:00
parent 44f219ca15
commit 29535e121b

View File

@@ -5,6 +5,7 @@ use chrono::{self, Timelike};
use dotenv;
use ipaddress;
use itertools::{self, Itertools};
use lettre::message::Mailboxes;
use lettre::{self, message};
use reqwest;
use serde_json::{self, json};
@@ -317,6 +318,7 @@ fn main() -> anyhow::Result<()> {
}).reduce(|acc, e|{format!("{}\n{}",acc,e)})
.unwrap_or("".to_string());
// return Ok(());
// Open file and write to it
let header = "NOME;ID_TALK;TEMPO DE RESPOSTA;TRANFERENCIA PELO BOT;PRIMEIRA RESPOSTA DO AGENTE";
let mut response_time_file = std::fs::OpenOptions::new().write(true).open(format!("./evaluations/{formatted_day_before}/response_time.csv")).expect("Failed to open response time file for write");
@@ -325,7 +327,7 @@ fn main() -> anyhow::Result<()> {
filtered_chats
.clone()
.skip(0)
.take(15)
.take(10)
.for_each(|result| {
let json = result.unwrap();
let talk_histories = &json["talk_histories"];
@@ -400,7 +402,7 @@ fn main() -> anyhow::Result<()> {
&formatted_day_before,
&BOT_EMAIL,
&BOT_EMAIL_PASSWORD,
"Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>",
"Wilson da Conceição Oliveira <wilson.oliveira@nova.net.br>, Isadora Moura de Moura <isadora.moura@nova.net.br>",
&output_zip_file_str,
);
return Ok(());
@@ -592,11 +594,13 @@ fn send_email(
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())
.to(format!("{to}").parse().unwrap())
.mailbox(to_header)
.subject(format!("Avaliacao atendimentos {day_before}"))
.multipart(
MultiPart::mixed()