Move smtp relay address to the configuration
authorGreg Burri <greg.burri@gmail.com>
Wed, 22 Nov 2023 14:38:38 +0000 (15:38 +0100)
committerGreg Burri <greg.burri@gmail.com>
Wed, 22 Nov 2023 14:38:38 +0000 (15:38 +0100)
src/config.rs
src/main.rs

index 187aaca..fbda142 100644 (file)
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
 #[derive(Debug, Clone, Deserialize, Serialize)]
 pub struct Config {
     pub pub_keys: Vec<String>,
+    pub smtp_relay_address: String,
     pub smtp_login: String,
     pub smtp_password: String,
 }
@@ -18,6 +19,7 @@ impl Config {
     pub fn default() -> Self {
         Config {
             pub_keys: vec![],
+            smtp_relay_address: "mail.something.com".to_string(),
             smtp_login: "login".to_string(),
             smtp_password: "password".to_string(),
         }
index 43ecb4a..1b09673 100644 (file)
@@ -62,6 +62,7 @@ fn main() -> Result<()> {
                 match send_email(
                     "Watchdog: Staking error",
                     &format!("Error: {}", error),
+                    &config.smtp_relay_address,
                     &config.smtp_login,
                     &config.smtp_password,
                 ) {
@@ -245,7 +246,13 @@ fn check_validators(pub_keys: &[String]) -> std::result::Result<(), CheckError>
     Ok(())
 }
 
-fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
+fn send_email(
+    title: &str,
+    body: &str,
+    smtp_relay_address: &str,
+    login: &str,
+    pass: &str,
+) -> Result<()> {
     let email = Message::builder()
         .message_id(None)
         .from("Staking Watchdog <redmine@d-lan.net>".parse()?)
@@ -257,7 +264,7 @@ fn send_email(title: &str, body: &str, login: &str, pass: &str) -> Result<()> {
     let creds = Credentials::new(login.to_string(), pass.to_string());
 
     // Open a remote connection to gmail
-    let mailer = SmtpTransport::relay("mail.infomaniak.com")?
+    let mailer = SmtpTransport::relay(smtp_relay_address)?
         .credentials(creds)
         .build();