1 use std
::time
::Duration
;
2 use derive_more
::Display
;
3 use lettre
::{transport
::smtp
::authentication
::Credentials
, Message
, SmtpTransport
, Transport
};
7 #[derive(Debug, Display)]
9 ParseError(lettre
::address
::AddressError
),
10 SmtpError(lettre
::transport
::smtp
::Error
),
11 Email(lettre
::error
::Error
),
14 impl From
<lettre
::address
::AddressError
> for Error
{
15 fn from(error
: lettre
::address
::AddressError
) -> Self {
16 Error
::ParseError(error
)
20 impl From
<lettre
::transport
::smtp
::Error
> for Error
{
21 fn from(error
: lettre
::transport
::smtp
::Error
) -> Self {
22 Error
::SmtpError(error
)
26 impl From
<lettre
::error
::Error
> for Error
{
27 fn from(error
: lettre
::error
::Error
) -> Self {
32 pub fn send_validation(site_url
: &str, email
: &str, token
: &str, smtp_login
: &str, smtp_password
: &str) -> Result
<(), Error
> {
33 let email
= Message
::builder()
35 .from("recipes@gburri.org".parse()?
)
37 .subject("Recipes.gburri.org account validation")
38 .body(format!("Follow this link to confirm your inscription: {}/validation?token={}", site_url
, token
))?
;
40 let credentials
= Credentials
::new(smtp_login
.to_string(), smtp_password
.to_string());
42 let mailer
= SmtpTransport
::relay("mail.gandi.net")?
.credentials(credentials
).timeout(Some(consts
::SEND_EMAIL_TIMEOUT
)).build();
44 if let Err(error
) = mailer
.send(&email
) {
45 eprintln!("Error when sending E-mail:\n{:?}", &error
);