From 719708dfd030dcae3998579f6b2c6212c9fee4c8 Mon Sep 17 00:00:00 2001 From: Valentin Tolmer Date: Wed, 2 Aug 2023 10:26:31 +0200 Subject: [PATCH] server: Wrap a lettre error with a friendlier error --- server/src/infra/mail.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/infra/mail.rs b/server/src/infra/mail.rs index d71760e..ef489dd 100644 --- a/server/src/infra/mail.rs +++ b/server/src/infra/mail.rs @@ -1,5 +1,5 @@ use crate::infra::{cli::SmtpEncryption, configuration::MailOptions}; -use anyhow::{Ok, Result}; +use anyhow::{anyhow, Ok, Result}; use lettre::{ message::Mailbox, transport::smtp::authentication::Credentials, AsyncSmtpTransport, AsyncTransport, Message, Tokio1Executor, @@ -43,8 +43,15 @@ async fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOpti mailer = mailer.credentials(creds) } - mailer.port(options.port).build().send(email).await?; - Ok(()) + if let Err(e) = mailer.port(options.port).build().send(email).await { + if e.to_string().contains("CorruptMessage") { + Err(anyhow!("CorruptMessage returned by lettre, this usually means the SMTP encryption setting is wrong.").context(e)) + } else { + Err(e.into()) + } + } else { + Ok(()) + } } pub async fn send_password_reset_email(