From: Greg Burri <greg.burri@gmail.com>
Date: Tue, 1 Apr 2025 21:46:25 +0000 (+0200)
Subject: Better email title + translation
X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=98744974692e18aed4c525e15cc73c24081ed03e;p=recipes.git

Better email title + translation
---

diff --git a/backend/src/data/backup.rs b/backend/src/data/backup.rs
index 6826da0..3935567 100644
--- a/backend/src/data/backup.rs
+++ b/backend/src/data/backup.rs
@@ -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();
diff --git a/backend/src/email.rs b/backend/src/email.rs
index d9c0ea4..96f0b40 100644
--- a/backend/src/email.rs
+++ b/backend/src/email.rs
@@ -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());
diff --git a/backend/src/services/user.rs b/backend/src/services/user.rs
index abc094d..82a7192 100644
--- a/backend/src/services/user.rs
+++ b/backend/src/services/user.rs
@@ -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!(
diff --git a/backend/src/translation.rs b/backend/src/translation.rs
index ceba825..f8b2cb5 100644
--- a/backend/src/translation.rs
+++ b/backend/src/translation.rs
@@ -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,
diff --git a/backend/translation.ron b/backend/translation.ron
index 8580417..acbda14 100644
--- a/backend/translation.ron
+++ b/backend/translation.ron
@@ -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é"),