Skip to content

Commit

Permalink
chore(notifications): rename lettre to smtp
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Feb 15, 2024
1 parent e7cccee commit c39a046
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion core/notifications/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Config {
};
config.db.pg_con = db_con;
config.mongo_import.connection = mongodb_connection;
config.app.email_executor.lettre.password = email_password;
config.app.email_executor.smtp.password = email_password;

config.app.executor.fcm.load_creds()?;

Expand Down
4 changes: 2 additions & 2 deletions core/notifications/src/email_executor/config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};

use super::lettre::LettreConfig;
use super::smtp::SmtpConfig;

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct EmailExecutorConfig {
pub lettre: LettreConfig,
pub smtp: SmtpConfig,
}
6 changes: 3 additions & 3 deletions core/notifications/src/email_executor/error.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use thiserror::Error;

use super::lettre::error::LettreError;
use super::smtp::error::SmtpError;
use crate::user_notification_settings::error::*;

#[derive(Error, Debug)]
pub enum EmailExecutorError {
#[error("EmailExecutorError - LettreError: {0}")]
LettreError(#[from] LettreError),
#[error("EmailExecutorError - SmtpError: {0}")]
SmtpError(#[from] SmtpError),
#[error("EmailExecutorError - UserNotificationSettingsError: {0}")]
UserNotificationSettingsError(#[from] UserNotificationSettingsError),
}
12 changes: 6 additions & 6 deletions core/notifications/src/email_executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
mod config;
pub mod error;
mod lettre;
mod smtp;

use crate::{notification_event::*, primitives::*, user_notification_settings::*};

pub use config::*;
use error::*;
use lettre::LettreClient;
use smtp::SmtpClient;

#[derive(Clone)]
pub struct EmailExecutor {
pub config: EmailExecutorConfig,
lettre: LettreClient,
smtp: SmtpClient,
settings: UserNotificationSettingsRepo,
}

Expand All @@ -20,10 +20,10 @@ impl EmailExecutor {
config: EmailExecutorConfig,
settings: UserNotificationSettingsRepo,
) -> Result<Self, EmailExecutorError> {
let lettre = LettreClient::init(config.lettre.clone())?;
let smtp = SmtpClient::init(config.smtp.clone())?;
Ok(EmailExecutor {
config,
lettre,
smtp,
settings,
})
}
Expand All @@ -35,7 +35,7 @@ impl EmailExecutor {
}
let msg = event.to_localized_msg(settings.locale().unwrap_or_default());

self.lettre.send_email(msg).await?;
self.smtp.send_email(msg).await?;

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct LettreConfig {
pub struct SmtpConfig {
pub username: String,
pub password: String,
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum LettreError {
#[error("LettreError - Transport : {0}")]
pub enum SmtpError {
#[error("SmtpError - Transport : {0}")]
Transport(#[from] lettre::transport::smtp::Error),
#[error("LettreError - Lettre : {0}")]
#[error("SmtpError - Lettre : {0}")]
Lettre(#[from] lettre::error::Error),
#[error("LettreError - Address : {0}")]
#[error("SmtpError - Address : {0}")]
Address(#[from] lettre::address::AddressError),
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub use config::*;
use error::*;

#[derive(Clone)]
pub struct LettreClient {
pub struct SmtpClient {
client: AsyncSmtpTransport<Tokio1Executor>,
}

impl LettreClient {
pub fn init(config: LettreConfig) -> Result<Self, LettreError> {
impl SmtpClient {
pub fn init(config: SmtpConfig) -> Result<Self, SmtpError> {
let creds = Credentials::new(config.username, config.password);
let client: AsyncSmtpTransport<Tokio1Executor> =
AsyncSmtpTransport::<Tokio1Executor>::starttls_relay("smtp.gmail.com")?
Expand All @@ -27,7 +27,7 @@ impl LettreClient {
Ok(Self { client })
}

pub async fn send_email(&self, msg: LocalizedMessage) -> Result<(), LettreError> {
pub async fn send_email(&self, msg: LocalizedMessage) -> Result<(), SmtpError> {
let email = Message::builder()
.from(Mailbox::new(None, "some-email".parse()?))
.to(Mailbox::new(None, "some-email".parse()?))
Expand Down
1 change: 1 addition & 0 deletions core/notifications/src/grpc/server/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl From<proto::NotificationChannel> for UserNotificationChannel {
fn from(channel: proto::NotificationChannel) -> Self {
match channel {
proto::NotificationChannel::Push => UserNotificationChannel::Push,
proto::NotificationChannel::Email => UserNotificationChannel::Email,
}
}
}
Expand Down

0 comments on commit c39a046

Please sign in to comment.