fix errors
This commit is contained in:
parent
e92c4d1b0e
commit
2856ebbd18
|
@ -1,15 +1,14 @@
|
||||||
use axum::{
|
use axum::{
|
||||||
routing::post,
|
|
||||||
Router,
|
|
||||||
Form,
|
|
||||||
response::{IntoResponse, Redirect, AppendHeaders},
|
|
||||||
http::header::SET_COOKIE,
|
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::message::Mailbox;
|
||||||
|
use lettre::transport::smtp::AsyncSmtpTransport;
|
||||||
|
use lettre::{AsyncTransport, Message, Tokio1Executor};
|
||||||
|
use serde::Deserialize;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
|
@ -40,9 +39,8 @@ async fn handle_form(Form(form_data): Form<FormData>) -> impl IntoResponse {
|
||||||
Err(_) => (
|
Err(_) => (
|
||||||
AppendHeaders([(SET_COOKIE, "is=err")]),
|
AppendHeaders([(SET_COOKIE, "is=err")]),
|
||||||
Redirect::to("/contact.html"),
|
Redirect::to("/contact.html"),
|
||||||
)
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_email(form_data: FormData) -> Result<(), Box<dyn Error>> {
|
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")
|
.subject("New Website Form Inquiry")
|
||||||
.body(format!(
|
.body(format!(
|
||||||
"Name: {}/nEmail: {}/nMessage: {}",
|
"Name: {}/nEmail: {}/nMessage: {}",
|
||||||
form_data.name,
|
form_data.name, form_data.email, form_data.message
|
||||||
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")?
|
let mailer = AsyncSmtpTransport::<Tokio1Executor>::relay("smtp.distrust.co")?
|
||||||
|
.credentials(credentials)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
mailer.send(email).await?;
|
mailer.send(email).await?;
|
||||||
|
|
Loading…
Reference in New Issue