From: Greg Burri Date: Wed, 22 Nov 2023 14:38:38 +0000 (+0100) Subject: Move smtp relay address to the configuration X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=fa183b35d56d26813de3d100c668d7d8f002cf13;p=stakingWatchdog.git Move smtp relay address to the configuration --- diff --git a/src/config.rs b/src/config.rs index 187aaca..fbda142 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 pub_keys: Vec, + 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(), } diff --git a/src/main.rs b/src/main.rs index 43ecb4a..1b09673 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 ".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();