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 { tokio::task::spawn(async move {
loop { loop {
let mut time_to_wait = time_of_day - chrono::Local::now().time(); 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}")] #[error("Email error: {0}")]
Email(#[from] lettre::error::Error), 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( pub async fn send_email(
email: &str, email: &str,
title: &str,
message: &str, message: &str,
smtp_relay_address: &str, smtp_relay_address: &str,
smtp_login: &str, smtp_login: &str,
@ -26,9 +30,9 @@ pub async fn send_email(
) -> Result<(), Error> { ) -> Result<(), Error> {
let email = Message::builder() let email = Message::builder()
.message_id(None) .message_id(None)
.from("recipes@gburri.org".parse()?) .from("recipes@recipes.gburri.org".parse()?)
.to(email.parse()?) .to(email.parse()?)
.subject("recipes.gburri.org account validation") .subject(title)
.body(message.to_string())?; .body(message.to_string())?;
let credentials = Credentials::new(smtp_login.to_string(), smtp_password.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(); let email = form_data.email.clone();
match email::send_email( match email::send_email(
&email, &email,
context.tr.t(Sentence::SignUpEmailTitle),
&context.tr.tp( &context.tr.tp(
Sentence::SignUpFollowEmailLink, Sentence::SignUpFollowEmailLink,
&[Box::new(format!( &[Box::new(format!(
@ -481,6 +482,7 @@ pub async fn ask_reset_password_post(
let url = utils::get_url_from_host(&host); let url = utils::get_url_from_host(&host);
match email::send_email( match email::send_email(
&form_data.email, &form_data.email,
context.tr.t(Sentence::AskResetEmailTitle),
&context.tr.tp( &context.tr.tp(
Sentence::AskResetFollowEmailLink, Sentence::AskResetFollowEmailLink,
&[Box::new(format!( &[Box::new(format!(
@ -793,6 +795,7 @@ pub async fn edit_user_post(
let email = form_data.email.clone(); let email = form_data.email.clone();
match email::send_email( match email::send_email(
&email, &email,
context.tr.t(Sentence::ProfileFollowEmailTitle),
&context.tr.tp( &context.tr.tp(
Sentence::ProfileFollowEmailLink, Sentence::ProfileFollowEmailLink,
&[Box::new(format!( &[Box::new(format!(

View file

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

View file

@ -41,6 +41,7 @@
(SignUpTitle, "Sign up"), (SignUpTitle, "Sign up"),
(SignUpButton, "Sign up"), (SignUpButton, "Sign up"),
(SignUpEmailSent, "An email has been sent, follow the link to validate your account"), (SignUpEmailSent, "An email has been sent, follow the link to validate your account"),
(SignUpEmailTitle, "Cooking Recipes: Account validation"),
(SignUpFollowEmailLink, "Follow this link to confirm your inscription, {}"), (SignUpFollowEmailLink, "Follow this link to confirm your inscription, {}"),
(SignUpEmailValidationSuccess, "Email validation successful, your account has been created"), (SignUpEmailValidationSuccess, "Email validation successful, your account has been created"),
(SignUpValidationExpired, "The validation has expired. Try to sign up again"), (SignUpValidationExpired, "The validation has expired. Try to sign up again"),
@ -54,6 +55,7 @@
(AskResetButton, "Ask reset"), (AskResetButton, "Ask reset"),
(AskResetAlreadyLoggedInError, "Can't ask to reset password when already logged in"), (AskResetAlreadyLoggedInError, "Can't ask to reset password when already logged in"),
(AskResetEmailAlreadyResetError, "The password has already been reset for this email"), (AskResetEmailAlreadyResetError, "The password has already been reset for this email"),
(AskResetEmailTitle, "Cooking Recipes: Reset password"),
(AskResetFollowEmailLink, "Follow this link to reset your password, {}"), (AskResetFollowEmailLink, "Follow this link to reset your password, {}"),
(AskResetEmailSent, "An email has been sent, follow the link to reset your password"), (AskResetEmailSent, "An email has been sent, follow the link to reset your password"),
(AskResetTokenMissing, "Reset token missing"), (AskResetTokenMissing, "Reset token missing"),
@ -66,6 +68,7 @@
(ProfileEmail, "Email (need to be revalidated if changed)"), (ProfileEmail, "Email (need to be revalidated if changed)"),
(ProfileDefaultServings, "Default servings"), (ProfileDefaultServings, "Default servings"),
(ProfileNewPassword, "New password (minimum {} characters)"), (ProfileNewPassword, "New password (minimum {} characters)"),
(ProfileFollowEmailTitle, "Cooking Recipes: Email validation"),
(ProfileFollowEmailLink, "Follow this link to validate this email address, {}"), (ProfileFollowEmailLink, "Follow this link to validate this email address, {}"),
(ProfileEmailSent, "An email has been sent, follow the link to validate your new email"), (ProfileEmailSent, "An email has been sent, follow the link to validate your new email"),
(ProfileSaved, "Profile saved"), (ProfileSaved, "Profile saved"),
@ -177,6 +180,7 @@
(SignUpTitle, "Inscription"), (SignUpTitle, "Inscription"),
(SignUpButton, "Valider"), (SignUpButton, "Valider"),
(SignUpEmailSent, "Un email a été envoyé, suivez le lien pour valider votre compte"), (SignUpEmailSent, "Un email a été envoyé, suivez le lien pour valider votre compte"),
(SignUpEmailTitle, "Recettes de Cuisine: Validation du compte"),
(SignUpFollowEmailLink, "Suivez ce lien pour valider votre inscription, {}"), (SignUpFollowEmailLink, "Suivez ce lien pour valider votre inscription, {}"),
(SignUpEmailValidationSuccess, "La validation de votre email s'est déroulée avec succès, votre compte a été créé"), (SignUpEmailValidationSuccess, "La validation de votre email s'est déroulée avec succès, votre compte a été créé"),
(SignUpValidationExpired, "La validation a expiré. Essayez de vous inscrire à nouveau"), (SignUpValidationExpired, "La validation a expiré. Essayez de vous inscrire à nouveau"),
@ -190,6 +194,7 @@
(AskResetButton, "Demander la réinitialisation"), (AskResetButton, "Demander la réinitialisation"),
(AskResetAlreadyLoggedInError, "Impossible de demander une réinitialisation du mot de passe lorsque déjà connecté"), (AskResetAlreadyLoggedInError, "Impossible de demander une réinitialisation du mot de passe lorsque déjà connecté"),
(AskResetEmailAlreadyResetError, "Le mot de passe a déjà été réinitialisé pour cette adresse email"), (AskResetEmailAlreadyResetError, "Le mot de passe a déjà été réinitialisé pour cette adresse email"),
(AskResetEmailTitle, "Recettes de Cuisine: Réinitialisation du mot de passe"),
(AskResetFollowEmailLink, "Suivez ce lien pour réinitialiser votre mot de passe, {}"), (AskResetFollowEmailLink, "Suivez ce lien pour réinitialiser votre mot de passe, {}"),
(AskResetEmailSent, "Un email a été envoyé, suivez le lien pour réinitialiser votre mot de passe"), (AskResetEmailSent, "Un email a été envoyé, suivez le lien pour réinitialiser votre mot de passe"),
(AskResetTokenMissing, "Jeton de réinitialisation manquant"), (AskResetTokenMissing, "Jeton de réinitialisation manquant"),
@ -202,6 +207,7 @@
(ProfileEmail, "Email (doit être revalidé si changé)"), (ProfileEmail, "Email (doit être revalidé si changé)"),
(ProfileDefaultServings, "Nombre de portions par défaut"), (ProfileDefaultServings, "Nombre de portions par défaut"),
(ProfileNewPassword, "Nouveau mot de passe (minimum {} caractères)"), (ProfileNewPassword, "Nouveau mot de passe (minimum {} caractères)"),
(ProfileFollowEmailTitle, "Recettes de Cuisine: Validation de l'adresse email"),
(ProfileFollowEmailLink, "Suivez ce lien pour valider l'adresse email, {}"), (ProfileFollowEmailLink, "Suivez ce lien pour valider l'adresse email, {}"),
(ProfileEmailSent, "Un email a été envoyé, suivez le lien pour valider la nouvelle adresse email"), (ProfileEmailSent, "Un email a été envoyé, suivez le lien pour valider la nouvelle adresse email"),
(ProfileSaved, "Profile sauvegardé"), (ProfileSaved, "Profile sauvegardé"),