From: Greg Burri Date: Wed, 22 Nov 2023 14:38:29 +0000 (+0100) Subject: Move smtp relay address to the configuration X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=b002ffd53caf641b377dead145055668fe73228c;p=stakingWatchdogWatchdog.git Move smtp relay address to the configuration --- diff --git a/src/config.rs b/src/config.rs index dd9b167..9b85549 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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(), } diff --git a/src/main.rs b/src/main.rs index 494737e..ac77882 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 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 ".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();