From 2856ebbd188288b50f251d1286280a19a233b510 Mon Sep 17 00:00:00 2001 From: Anton Livaja Date: Sat, 8 Jun 2024 20:17:16 -0400 Subject: [PATCH] fix errors --- crates/web-form/src/main.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/crates/web-form/src/main.rs b/crates/web-form/src/main.rs index b7f5d7f..675d114 100644 --- a/crates/web-form/src/main.rs +++ b/crates/web-form/src/main.rs @@ -1,15 +1,14 @@ use axum::{ - routing::post, - Router, - Form, - response::{IntoResponse, Redirect, AppendHeaders}, http::header::SET_COOKIE, + response::{AppendHeaders, IntoResponse, Redirect}, + routing::post, + Form, Router, }; -use serde::Deserialize; -use lettre::{Message, AsyncTransport, Tokio1Executor}; -use lettre::transport::smtp::AsyncSmtpTransport; use lettre::message::Mailbox; +use lettre::transport::smtp::AsyncSmtpTransport; +use lettre::{AsyncTransport, Message, Tokio1Executor}; +use serde::Deserialize; use std::error::Error; use std::net::SocketAddr; @@ -40,9 +39,8 @@ async fn handle_form(Form(form_data): Form) -> impl IntoResponse { Err(_) => ( AppendHeaders([(SET_COOKIE, "is=err")]), Redirect::to("/contact.html"), - ) + ), } - } async fn send_email(form_data: FormData) -> Result<(), Box> { @@ -53,12 +51,16 @@ async fn send_email(form_data: FormData) -> Result<(), Box> { .subject("New Website Form Inquiry") .body(format!( "Name: {}/nEmail: {}/nMessage: {}", - form_data.name, - form_data.email, - form_data.message + form_data.name, form_data.email, form_data.message ))?; + let credentials = lettre::transport::smtp::authentication::Credentials::new( + std::env::var("WEBMAIL_USERNAME")?, + std::env::var("WEBMAIL_PASSWORD")?, + ); + let mailer = AsyncSmtpTransport::::relay("smtp.distrust.co")? + .credentials(credentials) .build(); mailer.send(email).await?;