Move email config

This commit is contained in:
Mo 2023-02-26 15:13:49 +01:00
parent 9f195fffce
commit 338cadaf51
2 changed files with 8 additions and 10 deletions

View file

@ -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<Self> {
pub async fn build(email_config: config::Email) -> Result<Self> {
// 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!")?);

View file

@ -19,7 +19,7 @@ pub struct AppState {
impl AppState {
/// Try to build the app state.
pub async fn build(config: Config) -> Result<Self> {
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.