attempt at fixing confirmation emails by setting email headers, link for manual confirmation email and cut next release #29
1 changed files with 34 additions and 29 deletions
cleanup email a bit
commit
d3c52fb4aa
45
src/email.rs
45
src/email.rs
|
|
@ -3,26 +3,11 @@ use crate::server_config::EmailConfig;
|
|||
use crate::template;
|
||||
use crate::util::SerializableUrl;
|
||||
use handlebars::Handlebars;
|
||||
use lettre::message::header::{Header, HeaderName, HeaderValue};
|
||||
use lettre::message::header::{Header, HeaderName, HeaderValue, UserAgent};
|
||||
use lettre::message::{Mailbox, SinglePart};
|
||||
use lettre::{Address, AsyncTransport};
|
||||
use log::warn;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub(crate) struct EmailData {
|
||||
pub(crate) confirmation_link: SerializableUrl,
|
||||
}
|
||||
|
||||
pub(crate) async fn send_confirmation_email(
|
||||
hb: &Handlebars<'_>,
|
||||
contact_address: Address,
|
||||
email_config: &EmailConfig,
|
||||
email_data: &EmailData,
|
||||
) -> actix_web::Result<(), EmailError> {
|
||||
let to_mailbox = Mailbox::new(None, contact_address);
|
||||
|
||||
let email_body = hb.render(template::EMAIL_PLAIN, &email_data)?;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct AutoGeneratedHeader(String);
|
||||
|
||||
|
|
@ -46,23 +31,43 @@ pub(crate) async fn send_confirmation_email(
|
|||
}
|
||||
}
|
||||
|
||||
let ua_header =
|
||||
lettre::message::header::UserAgent::from(String::from("fs-infmath-jobboerse via sendmail"));
|
||||
fn user_agent() -> UserAgent {
|
||||
String::from("fs-infmath-jobboerse via sendmail").into()
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub(crate) struct EmailData {
|
||||
pub(crate) confirmation_link: SerializableUrl,
|
||||
}
|
||||
|
||||
pub(crate) async fn send_confirmation_email(
|
||||
hb: &Handlebars<'_>,
|
||||
contact_address: Address,
|
||||
email_config: &EmailConfig,
|
||||
email_data: &EmailData,
|
||||
) -> actix_web::Result<(), EmailError> {
|
||||
// receiver of the confirmation e-mail
|
||||
let to_mailbox = Mailbox::new(None, contact_address);
|
||||
|
||||
let email_body = hb.render(template::EMAIL_PLAIN, &email_data)?;
|
||||
|
||||
let message = lettre::Message::builder()
|
||||
.from(email_config.from.to_owned())
|
||||
.to(to_mailbox)
|
||||
.subject(&email_config.subject)
|
||||
.header(ua_header.clone())
|
||||
.header(user_agent())
|
||||
.header(AutoGeneratedHeader::default())
|
||||
.singlepart(SinglePart::plain(email_body))?;
|
||||
|
||||
lettre::AsyncSendmailTransport::new().send(message).await?;
|
||||
|
||||
// successfully send a confirmation e-mail now send a notice to our-self
|
||||
|
||||
let message = lettre::Message::builder()
|
||||
.from(email_config.from.to_owned())
|
||||
.to(email_config.from.to_owned())
|
||||
.subject(&email_config.subject)
|
||||
.header(ua_header)
|
||||
.header(user_agent())
|
||||
.header(AutoGeneratedHeader::default())
|
||||
.singlepart(SinglePart::plain(
|
||||
"Automatischer Hinweis: Eine neue Stellenausschreibung wurde zur Jobbörse eingereicht!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue