turn project into workspace
This commit is contained in:
parent
8e7557a36e
commit
4fa5617112
18
Cargo.toml
18
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"
|
||||
]
|
|
@ -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"
|
|
@ -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<FormData>) -> 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<dyn Error>> {
|
||||
let email = Message::builder()
|
||||
.from(form_data.email.parse::<Mailbox>()?)
|
||||
.from("webmail@distrust.co".parse()?)
|
||||
.reply_to(form_data.email.parse::<Mailbox>()?)
|
||||
.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)?;
|
Loading…
Reference in New Issue