server: Wrap a lettre error with a friendlier error

This commit is contained in:
Valentin Tolmer
2023-08-02 10:26:31 +02:00
committed by nitnelave
parent b82cb83318
commit 719708dfd0
+10 -3
View File
@@ -1,5 +1,5 @@
use crate::infra::{cli::SmtpEncryption, configuration::MailOptions}; use crate::infra::{cli::SmtpEncryption, configuration::MailOptions};
use anyhow::{Ok, Result}; use anyhow::{anyhow, Ok, Result};
use lettre::{ use lettre::{
message::Mailbox, transport::smtp::authentication::Credentials, AsyncSmtpTransport, message::Mailbox, transport::smtp::authentication::Credentials, AsyncSmtpTransport,
AsyncTransport, Message, Tokio1Executor, AsyncTransport, Message, Tokio1Executor,
@@ -43,8 +43,15 @@ async fn send_email(to: Mailbox, subject: &str, body: String, options: &MailOpti
mailer = mailer.credentials(creds) mailer = mailer.credentials(creds)
} }
mailer.port(options.port).build().send(email).await?; if let Err(e) = mailer.port(options.port).build().send(email).await {
Ok(()) 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( pub async fn send_password_reset_email(