From b002ffd53caf641b377dead145055668fe73228c Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Wed, 22 Nov 2023 15:38:29 +0100 Subject: [PATCH] Move smtp relay address to the configuration --- src/config.rs | 2 ++ src/main.rs | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) 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(); -- 2.45.2