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
63
src/email.rs
63
src/email.rs
|
|
@ -3,11 +3,38 @@ 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(Clone, Debug)]
|
||||
struct AutoGeneratedHeader(String);
|
||||
|
||||
impl Default for AutoGeneratedHeader {
|
||||
fn default() -> Self {
|
||||
Self("auto-generated".into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Header for AutoGeneratedHeader {
|
||||
fn name() -> HeaderName {
|
||||
HeaderName::new_from_ascii_str("Auto-Submitted")
|
||||
}
|
||||
|
||||
fn parse(s: &str) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
|
||||
Ok(Self(s.into()))
|
||||
}
|
||||
|
||||
fn display(&self) -> HeaderValue {
|
||||
HeaderValue::new(Self::name(), self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
fn user_agent() -> UserAgent {
|
||||
String::from("fs-infmath-jobboerse via sendmail").into()
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub(crate) struct EmailData {
|
||||
pub(crate) confirmation_link: SerializableUrl,
|
||||
|
|
@ -19,50 +46,28 @@ pub(crate) async fn send_confirmation_email(
|
|||
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)?;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct AutoGeneratedHeader(String);
|
||||
|
||||
impl Default for AutoGeneratedHeader {
|
||||
fn default() -> Self {
|
||||
Self("auto-generated".into())
|
||||
}
|
||||
}
|
||||
|
||||
impl Header for AutoGeneratedHeader {
|
||||
fn name() -> HeaderName {
|
||||
HeaderName::new_from_ascii_str("Auto-Submitted")
|
||||
}
|
||||
|
||||
fn parse(s: &str) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> {
|
||||
Ok(Self(s.into()))
|
||||
}
|
||||
|
||||
fn display(&self) -> HeaderValue {
|
||||
HeaderValue::new(Self::name(), self.0.clone())
|
||||
}
|
||||
}
|
||||
|
||||
let ua_header =
|
||||
lettre::message::header::UserAgent::from(String::from("fs-infmath-jobboerse via sendmail"));
|
||||
|
||||
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