Better email title + translation

This commit is contained in:
Greg Burri 2025-04-01 23:46:25 +02:00
parent c7b6f58655
commit 9874497469
5 changed files with 18 additions and 3 deletions

View file

@ -24,7 +24,6 @@ where
);
}
// Can also user tokio::spawn_blocking if needed.
tokio::task::spawn(async move {
loop {
let mut time_to_wait = time_of_day - chrono::Local::now().time();

View file

@ -17,8 +17,12 @@ pub enum Error {
#[error("Email error: {0}")]
Email(#[from] lettre::error::Error),
}
/// A function to send an email using the given SMTP address.
/// It may timeout if the SMTP server is not reachable, see [const::SEND_EMAIL_TIMEOUT].
pub async fn send_email(
email: &str,
title: &str,
message: &str,
smtp_relay_address: &str,
smtp_login: &str,
@ -26,9 +30,9 @@ pub async fn send_email(
) -> Result<(), Error> {
let email = Message::builder()
.message_id(None)
.from("recipes@gburri.org".parse()?)
.from("recipes@recipes.gburri.org".parse()?)
.to(email.parse()?)
.subject("recipes.gburri.org account validation")
.subject(title)
.body(message.to_string())?;
let credentials = Credentials::new(smtp_login.to_string(), smtp_password.to_string());

View file

@ -152,6 +152,7 @@ pub async fn sign_up_post(
let email = form_data.email.clone();
match email::send_email(
&email,
context.tr.t(Sentence::SignUpEmailTitle),
&context.tr.tp(
Sentence::SignUpFollowEmailLink,
&[Box::new(format!(
@ -481,6 +482,7 @@ pub async fn ask_reset_password_post(
let url = utils::get_url_from_host(&host);
match email::send_email(
&form_data.email,
context.tr.t(Sentence::AskResetEmailTitle),
&context.tr.tp(
Sentence::AskResetFollowEmailLink,
&[Box::new(format!(
@ -793,6 +795,7 @@ pub async fn edit_user_post(
let email = form_data.email.clone();
match email::send_email(
&email,
context.tr.t(Sentence::ProfileFollowEmailTitle),
&context.tr.tp(
Sentence::ProfileFollowEmailLink,
&[Box::new(format!(

View file

@ -38,6 +38,7 @@ pub enum Sentence {
SignUpTitle,
SignUpButton,
SignUpEmailSent,
SignUpEmailTitle,
SignUpFollowEmailLink,
SignUpEmailValidationSuccess,
SignUpValidationExpired,
@ -66,6 +67,7 @@ pub enum Sentence {
AskResetButton,
AskResetAlreadyLoggedInError,
AskResetEmailAlreadyResetError,
AskResetEmailTitle,
AskResetFollowEmailLink,
AskResetEmailSent,
AskResetTokenMissing,
@ -79,6 +81,7 @@ pub enum Sentence {
ProfileEmail,
ProfileDefaultServings,
ProfileNewPassword,
ProfileFollowEmailTitle,
ProfileFollowEmailLink,
ProfileEmailSent,
ProfileSaved,