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

index dd9b167..9b85549 100644 (file)
@@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
 #[derive(Debug, Clone, Deserialize, Serialize)]
 pub struct Config {
     pub staking_address: 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 {
             staking_address: "192.168.2.102:8739".to_string(),
+            smtp_relay_address: "mail.something.com".to_string(),
             smtp_login: "login".to_string(),
             smtp_password: "password".to_string(),
         }
index 494737e..ac77882 100644 (file)
@@ -82,6 +82,7 @@ fn main() -> Result<()> {
                     match send_email(
                         "Watchdog Watchdog: Check alive error",
                         &format!("Error: {}", error),
+                        &config.smtp_relay_address,
                         &config.smtp_login,
                         &config.smtp_password,
                     ) {
@@ -169,7 +170,13 @@ fn ping(socket: &UdpSocket, rng: &mut ThreadRng) -> std::result::Result<Duration
     }
 }
 
-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 Watchdog <redmine@d-lan.net>".parse()?)
@@ -181,7 +188,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();