diff --git a/src/mailer.rs b/src/mailer.rs index cf3e0dc..bd2e668 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -10,7 +10,7 @@ use lettre::{ use tracing::info; use crate::{ - config::{Config, StateConfig}, + config::{self, StateConfig}, forms::PersistentFieldContents, }; @@ -24,15 +24,15 @@ pub struct Mailer { impl Mailer { /// Tries to initialize the mailer. - pub async fn build(config: &Config) -> Result { + pub async fn build(email_config: config::Email) -> Result { // Mail server credentials for login. let credentials = Credentials::new( - config.email.credentials.username.clone(), - config.email.credentials.password.clone(), + email_config.credentials.username, + email_config.credentials.password, ); // Establish the connection. - let mailer = ASmtpTransport::relay(&config.email.credentials.domain) + let mailer = ASmtpTransport::relay(&email_config.credentials.domain) .context("Failed to connect to the email server!")? .credentials(credentials) .build(); @@ -45,14 +45,12 @@ impl Mailer { // Set the From and To mailboxes for every sent mail. let message_builder = Message::builder() .from( - config - .email + email_config .from .parse() .context("Failed to parse the From mailbox!")?, ) - .to(config - .email + .to(email_config .to .parse() .context("Failed to parse the To mailbox!")?); diff --git a/src/states.rs b/src/states.rs index d47c5f8..d293078 100644 --- a/src/states.rs +++ b/src/states.rs @@ -19,7 +19,7 @@ pub struct AppState { impl AppState { /// Try to build the app state. pub async fn build(config: Config) -> Result { - let mailer = Arc::new(Mailer::build(&config).await?); + let mailer = Arc::new(Mailer::build(config.email).await?); let state_config = Arc::new(config.state_config); // Mutex for write access.