X-Git-Url: http://git.euphorik.ch/?p=recipes.git;a=blobdiff_plain;f=backend%2Fsrc%2Femail.rs;fp=backend%2Fsrc%2Femail.rs;h=a0043f7e09ec7409d6fe59230aecb5f2dc2b8b94;hp=0000000000000000000000000000000000000000;hb=45d4867cb37ce8d7007c4d98de70d81d0b705b92;hpb=b1ffd1a04a55d6653ed55ea99f09550e5a8a9a96 diff --git a/backend/src/email.rs b/backend/src/email.rs new file mode 100644 index 0000000..a0043f7 --- /dev/null +++ b/backend/src/email.rs @@ -0,0 +1,22 @@ +use lettre::{transport::smtp::{authentication::Credentials}, Message, SmtpTransport, Transport}; + +/// +pub fn send_validation(site_url: &str, email: &str, token: &str, smtp_login: &str, smtp_password: &str) -> Result<(), Box> { + + let email = Message::builder() + .message_id(None) + .from("recipes@gburri.org".parse()?) + .to(email.parse()?) + .subject("Recipes.gburri.org account validation") + .body(format!("Follow this link to confirm your inscription: {}/validation?token={}", site_url, token))?; + + let credentials = Credentials::new(smtp_login.to_string(), smtp_password.to_string()); + + let mailer = SmtpTransport::relay("mail.gandi.net")?.credentials(credentials).build(); + + if let Err(error) = mailer.send(&email) { + println!("Error when sending E-mail:\n{:?}", &error); + } + + Ok(()) +}