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,

View file

@ -41,6 +41,7 @@
(SignUpTitle, "Sign up"),
(SignUpButton, "Sign up"),
(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, {}"),
(SignUpEmailValidationSuccess, "Email validation successful, your account has been created"),
(SignUpValidationExpired, "The validation has expired. Try to sign up again"),
@ -54,6 +55,7 @@
(AskResetButton, "Ask reset"),
(AskResetAlreadyLoggedInError, "Can't ask to reset password when already logged in"),
(AskResetEmailAlreadyResetError, "The password has already been reset for this email"),
(AskResetEmailTitle, "Cooking Recipes: Reset password"),
(AskResetFollowEmailLink, "Follow this link to reset your password, {}"),
(AskResetEmailSent, "An email has been sent, follow the link to reset your password"),
(AskResetTokenMissing, "Reset token missing"),
@ -66,6 +68,7 @@
(ProfileEmail, "Email (need to be revalidated if changed)"),
(ProfileDefaultServings, "Default servings"),
(ProfileNewPassword, "New password (minimum {} characters)"),
(ProfileFollowEmailTitle, "Cooking Recipes: Email validation"),
(ProfileFollowEmailLink, "Follow this link to validate this email address, {}"),
(ProfileEmailSent, "An email has been sent, follow the link to validate your new email"),
(ProfileSaved, "Profile saved"),
@ -177,6 +180,7 @@
(SignUpTitle, "Inscription"),
(SignUpButton, "Valider"),
(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, {}"),
(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"),
@ -190,6 +194,7 @@
(AskResetButton, "Demander la réinitialisation"),
(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"),
(AskResetEmailTitle, "Recettes de Cuisine: Réinitialisation du 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"),
(AskResetTokenMissing, "Jeton de réinitialisation manquant"),
@ -202,6 +207,7 @@
(ProfileEmail, "Email (doit être revalidé si changé)"),
(ProfileDefaultServings, "Nombre de portions par défaut"),
(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, {}"),
(ProfileEmailSent, "Un email a été envoyé, suivez le lien pour valider la nouvelle adresse email"),
(ProfileSaved, "Profile sauvegardé"),