Skip to content

Commit

Permalink
chore(notifications): remove password from notifications.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
thevaibhav-dixit committed Feb 16, 2024
1 parent 9cc2422 commit 923bda0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/notifications/notifications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ app:
email_executor:
smtp:
username: ""
password: ""
from_email: ""
2 changes: 2 additions & 0 deletions core/notifications/src/email_executor/smtp/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
pub struct SmtpConfig {
pub username: String,
#[serde(default)]
pub password: String,
pub from_email: String,
}
8 changes: 6 additions & 2 deletions core/notifications/src/email_executor/smtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use error::*;
#[derive(Clone)]
pub struct SmtpClient {
client: AsyncSmtpTransport<Tokio1Executor>,
from_email: String,
}

impl SmtpClient {
Expand All @@ -24,12 +25,15 @@ impl SmtpClient {
AsyncSmtpTransport::<Tokio1Executor>::starttls_relay("smtp.gmail.com")?
.credentials(creds)
.build();
Ok(Self { client })
Ok(Self {
client,
from_email: config.from_email,
})
}

pub async fn send_email(&self, msg: LocalizedMessage) -> Result<(), SmtpError> {
let email = Message::builder()
.from(Mailbox::new(None, "some-email".parse()?))
.from(Mailbox::new(None, self.from_email.parse()?))
.to(Mailbox::new(None, "some-email".parse()?))
.subject(msg.title)
.body(msg.body)?;
Expand Down

0 comments on commit 923bda0

Please sign in to comment.