Move email config
This commit is contained in:
parent
9f195fffce
commit
338cadaf51
2 changed files with 8 additions and 10 deletions
|
@ -10,7 +10,7 @@ use lettre::{
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, StateConfig},
|
config::{self, StateConfig},
|
||||||
forms::PersistentFieldContents,
|
forms::PersistentFieldContents,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -24,15 +24,15 @@ pub struct Mailer {
|
||||||
|
|
||||||
impl Mailer {
|
impl Mailer {
|
||||||
/// Tries to initialize the 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.
|
// Mail server credentials for login.
|
||||||
let credentials = Credentials::new(
|
let credentials = Credentials::new(
|
||||||
config.email.credentials.username.clone(),
|
email_config.credentials.username,
|
||||||
config.email.credentials.password.clone(),
|
email_config.credentials.password,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Establish the connection.
|
// 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!")?
|
.context("Failed to connect to the email server!")?
|
||||||
.credentials(credentials)
|
.credentials(credentials)
|
||||||
.build();
|
.build();
|
||||||
|
@ -45,14 +45,12 @@ impl Mailer {
|
||||||
// Set the From and To mailboxes for every sent mail.
|
// Set the From and To mailboxes for every sent mail.
|
||||||
let message_builder = Message::builder()
|
let message_builder = Message::builder()
|
||||||
.from(
|
.from(
|
||||||
config
|
email_config
|
||||||
.email
|
|
||||||
.from
|
.from
|
||||||
.parse()
|
.parse()
|
||||||
.context("Failed to parse the From mailbox!")?,
|
.context("Failed to parse the From mailbox!")?,
|
||||||
)
|
)
|
||||||
.to(config
|
.to(email_config
|
||||||
.email
|
|
||||||
.to
|
.to
|
||||||
.parse()
|
.parse()
|
||||||
.context("Failed to parse the To mailbox!")?);
|
.context("Failed to parse the To mailbox!")?);
|
||||||
|
|
|
@ -19,7 +19,7 @@ pub struct AppState {
|
||||||
impl AppState {
|
impl AppState {
|
||||||
/// Try to build the app state.
|
/// Try to build the app state.
|
||||||
pub async fn build(config: Config) -> Result<Self> {
|
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);
|
let state_config = Arc::new(config.state_config);
|
||||||
// Mutex for write access.
|
// Mutex for write access.
|
||||||
|
|
Loading…
Reference in a new issue