Skip to content

Commit

Permalink
Merge pull request #599 from BWStearns/bcc
Browse files Browse the repository at this point in the history
Add CC and BCC field to the mailers.
  • Loading branch information
jondot authored Jun 5, 2024
2 parents d4df226 + aec3eee commit 54a7828
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mailer/email_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ impl EmailSender {
)
.to(email.to.parse()?);

if let Some(bcc) = &email.bcc {
builder = builder.bcc(bcc.parse()?);
}

if let Some(cc) = &email.cc {
builder = builder.cc(cc.parse()?);
}

if let Some(reply_to) = &email.reply_to {
builder = builder.reply_to(reply_to.parse()?);
}
Expand Down Expand Up @@ -160,6 +168,8 @@ mod tests {
subject: "Email Subject".to_string(),
text: "Welcome".to_string(),
html: html.to_string(),
bcc: None,
cc: None,
};
assert!(sender.mail(&data).await.is_ok());

Expand Down
8 changes: 8 additions & 0 deletions src/mailer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub struct Args {
pub to: String,
pub reply_to: Option<String>,
pub locals: serde_json::Value,
pub bcc: Option<String>,
pub cc: Option<String>,
}

/// The structure representing an email details.
Expand All @@ -41,6 +43,10 @@ pub struct Email {
pub text: String,
/// HTML template
pub html: String,
/// BCC header to message
pub bcc: Option<String>,
/// CC header to message
pub cc: Option<String>,
}

/// The options struct for configuring the email sender.
Expand Down Expand Up @@ -91,6 +97,8 @@ pub trait Mailer {
subject: content.subject,
text: content.text,
html: content.html,
bcc: args.bcc.clone(),
cc: args.cc.clone(),
},
)
.await
Expand Down

0 comments on commit 54a7828

Please sign in to comment.