From 4fa5617112c15bb164304a418aaf065b3e52c15b Mon Sep 17 00:00:00 2001 From: Anton Livaja Date: Sat, 8 Jun 2024 19:01:51 -0400 Subject: [PATCH] turn project into workspace --- Cargo.toml | 18 +++++------------- Cargo.lock => crates/website-form/Cargo.lock | 0 crates/website-form/Cargo.toml | 14 ++++++++++++++ {src => crates/website-form/src}/main.rs | 19 ++++++++++++------- 4 files changed, 31 insertions(+), 20 deletions(-) rename Cargo.lock => crates/website-form/Cargo.lock (100%) create mode 100644 crates/website-form/Cargo.toml rename {src => crates/website-form/src}/main.rs (68%) diff --git a/Cargo.toml b/Cargo.toml index 55d1384..84f7bea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,6 @@ -[package] -name = "website-form" -version = "0.1.0" -edition = "2021" +[workspace] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } -lettre = "0.11.7" -axum = "0.7.5" -serde = { version = "1.0.201", features = ["derive"] } -serde_json = "1.0.117" -axum-server = "0.6.0" +resolver = "2" +members = [ + "crates/webform" +] \ No newline at end of file diff --git a/Cargo.lock b/crates/website-form/Cargo.lock similarity index 100% rename from Cargo.lock rename to crates/website-form/Cargo.lock diff --git a/crates/website-form/Cargo.toml b/crates/website-form/Cargo.toml new file mode 100644 index 0000000..55d1384 --- /dev/null +++ b/crates/website-form/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "website-form" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } +lettre = "0.11.7" +axum = "0.7.5" +serde = { version = "1.0.201", features = ["derive"] } +serde_json = "1.0.117" +axum-server = "0.6.0" diff --git a/src/main.rs b/crates/website-form/src/main.rs similarity index 68% rename from src/main.rs rename to crates/website-form/src/main.rs index a1490c7..fb0d099 100644 --- a/src/main.rs +++ b/crates/website-form/src/main.rs @@ -2,12 +2,11 @@ use axum::{ routing::post, Router, Form, - response::IntoResponse, - + response::{IntoResponse, Redirect}, }; use serde::Deserialize; -use lettre::{Message, SmtpTransport, Transport}; +use lettre::{Message, AsyncSmtpTransport, Transport}; use lettre::message::Mailbox; use std::error::Error; use std::net::SocketAddr; @@ -33,18 +32,24 @@ async fn main() { async fn handle_form(Form(form_data): Form) -> impl IntoResponse { match send_email(form_data).await { Ok(_) => format!("Form submitted successfully"), - Err(_) => format!("Error sending email."), + Err(_) => Redirect::to("/contact.html"), } } async fn send_email(form_data: FormData) -> Result<(), Box> { let email = Message::builder() - .from(form_data.email.parse::()?) + .from("webmail@distrust.co".parse()?) + .reply_to(form_data.email.parse::()?) .to("sales@distrust.co".parse()?) .subject("New Website Form Inquiry") - .body(format!("Name: {}/nEmail: {}/nMessage: {}", form_data.name, form_data.email, form_data.message))?; + .body(format!( + "Name: {}/nEmail: {}/nMessage: {}", + form_data.name, + form_data.email, + form_data.message + ))?; - let mailer = SmtpTransport::relay("smtp.distrust.co")? + let mailer = AsyncSmtpTransport::relay("smtp.distrust.co")? .build(); mailer.send(&email)?;