allow optional CC
This commit is contained in:
parent
c2d001b060
commit
b2631babd8
|
@ -48,6 +48,7 @@ struct State {
|
|||
username: String,
|
||||
password: String,
|
||||
target_address: String,
|
||||
cc: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -55,11 +56,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let username = std::env::var("WEBMAIL_USERNAME")?;
|
||||
let password = std::env::var("WEBMAIL_PASSWORD")?;
|
||||
let target_address = std::env::var("WEBMAIL_TARGET")?;
|
||||
let cc = std::env::var("WEBMAIL_CC").ok();
|
||||
|
||||
let state = State {
|
||||
username,
|
||||
password,
|
||||
target_address,
|
||||
cc,
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
|
@ -125,18 +128,21 @@ async fn send_email(form_data: FormData, state: &State) -> Result<(), Box<dyn Er
|
|||
];
|
||||
let body = content.map(|(a, b)| format!("{a}: {b}")).join("\n");
|
||||
|
||||
println!("Body: {body}");
|
||||
|
||||
let email = Message::builder()
|
||||
let mut email_builder = Message::builder()
|
||||
.from(username.parse()?)
|
||||
.reply_to(email)
|
||||
.to(state.target_address.parse()?)
|
||||
.subject("New Website Form Inquiry")
|
||||
.singlepart(
|
||||
SinglePart::builder()
|
||||
.header(ContentType::TEXT_PLAIN)
|
||||
.body(body),
|
||||
)?;
|
||||
.subject("New Website Form Inquiry");
|
||||
|
||||
if let Some(cc) = state.cc.as_ref() {
|
||||
email_builder = email_builder.cc(cc.parse()?);
|
||||
}
|
||||
|
||||
let email = email_builder.singlepart(
|
||||
SinglePart::builder()
|
||||
.header(ContentType::TEXT_PLAIN)
|
||||
.body(body),
|
||||
)?;
|
||||
|
||||
let credentials = lettre::transport::smtp::authentication::Credentials::new(
|
||||
username.clone(),
|
||||
|
|
Loading…
Reference in New Issue