fix errors
This commit is contained in:
parent
e92c4d1b0e
commit
2856ebbd18
|
@ -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<FormData>) -> impl IntoResponse {
|
|||
Err(_) => (
|
||||
AppendHeaders([(SET_COOKIE, "is=err")]),
|
||||
Redirect::to("/contact.html"),
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fn send_email(form_data: FormData) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -53,12 +51,16 @@ async fn send_email(form_data: FormData) -> Result<(), Box<dyn Error>> {
|
|||
.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::<Tokio1Executor>::relay("smtp.distrust.co")?
|
||||
.credentials(credentials)
|
||||
.build();
|
||||
|
||||
mailer.send(email).await?;
|
||||
|
|
Loading…
Reference in New Issue