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