1 use derive_more
::Display
;
2 use lettre
::{transport
::smtp
::authentication
::Credentials
, Message
, SmtpTransport
, Transport
};
3 use std
::time
::Duration
;
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(
38 ) -> Result
<(), Error
> {
39 let email
= Message
::builder()
41 .from("recipes@gburri.org".parse()?
)
43 .subject("Recipes.gburri.org account validation")
45 "Follow this link to confirm your inscription: {}/validation?token={}",
49 let credentials
= Credentials
::new(smtp_login
.to_string(), smtp_password
.to_string());
51 let mailer
= SmtpTransport
::relay("mail.gandi.net")?
52 .credentials(credentials
)
53 .timeout(Some(consts
::SEND_EMAIL_TIMEOUT
))
56 if let Err(error
) = mailer
.send(&email
) {
57 eprintln!("Error when sending E-mail:\n{:?}", &error
);