2 AsyncTransport
, Message
, Tokio1Executor
,
3 transport
::smtp
::{AsyncSmtpTransport
, authentication
::Credentials
},
5 use tracing
::{Level
, event
};
9 #[derive(Debug, thiserror::Error)]
11 #[error("Parse error: {0}")]
12 Parse(#[from] lettre::address::AddressError),
14 #[error("SMTP error: {0}")]
15 Smtp(#[from] lettre::transport::smtp::Error),
17 #[error("Email error: {0}")]
18 Email(#[from] lettre::error::Error),
21 /// A function to send an email using the given SMTP address.
22 /// It may timeout if the SMTP server is not reachable, see [const::SEND_EMAIL_TIMEOUT].
23 pub async
fn send_email(
27 smtp_relay_address
: &str,
30 ) -> Result
<(), Error
> {
31 let email
= Message
::builder()
33 .from("recipes@recipes.gburri.org".parse()?
)
36 .body(message
.to_string())?
;
38 let credentials
= Credentials
::new(smtp_login
.to_string(), smtp_password
.to_string());
40 let mailer
= AsyncSmtpTransport
::<Tokio1Executor
>::relay(smtp_relay_address
)?
41 .credentials(credentials
)
42 .timeout(Some(consts
::SEND_EMAIL_TIMEOUT
))
45 if let Err(error
) = mailer
.send(email
).await
{
46 event!(Level
::ERROR
, "Error when sending E-mail: {}", &error
);