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,14 +128,17 @@ 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(
|
||||
.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),
|
||||
|
|
Loading…
Reference in New Issue