use { crate::MailExecutor, actix::{Handler, Message}, uuid::Uuid, }; #[derive(Debug)] pub struct Invite { pub bind_token: Uuid, pub email: String, pub inviter_name: String, } impl Message for Invite { type Result = Result<(), String>; } impl Handler for MailExecutor { type Result = Result<(), String>; fn handle(&mut self, msg: Invite, _ctx: &mut Self::Context) -> Self::Result { use lettre::Transport; let transport = &mut self.transport; let from = self.config.from.as_str(); let addr = jirs_config::web::Configuration::read().full_addr(); let html = format!( r#"

You have been invited to project by {inviter_name}!

Please click this link: {addr}/invite?token={bind_token}

"#, bind_token = msg.bind_token, inviter_name = msg.inviter_name, addr = addr, ); let email = lettre_email::Email::builder() .from(from) .to(msg.email.as_str()) .html(html.as_str()) .subject("Invitation to JIRS project") .build() .map_err(|_| "Email is not valid".to_string())?; transport .send(email.into()) .map(|_| ()) .map_err(|e| format!("Mailer: {}", e)) } }