From 02b7127d302fdc10f16174451bda2dacd193955a Mon Sep 17 00:00:00 2001 From: Nickiel12 Date: Mon, 11 Sep 2023 16:56:59 -0700 Subject: [PATCH] added html template with attachment --- time_tracker/src/main.rs | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/time_tracker/src/main.rs b/time_tracker/src/main.rs index 696e4d9..4ea2a49 100644 --- a/time_tracker/src/main.rs +++ b/time_tracker/src/main.rs @@ -365,18 +365,43 @@ fn send_email_summary(config: &Config, body_content: Vec) { let attachment = Attachment::new("TimeSummary.csv".to_string()).body(data, ContentType::parse("text/csv").unwrap()); + const HTML: &str = r#" + !DOCTYPE html> + + + + + Hello from Lettre! + + +
+

Hello from Lettre!

+

A mailer library for Rust

+
+ +"#; + let email = Message::builder() - .from("NoReplay ".parse().unwrap()) - .to("Nicholas Young ".parse().unwrap()) + .from("NoReply@nickiel.net ".parse().unwrap()) + .to(config.email_addr.parse().unwrap()) .subject("Testing email") - .header(ContentType::TEXT_PLAIN) - .singlepart(attachment) - .unwrap(); - // .multipart( - // MultiPart::mixed() - // .singlepart(SinglePart::plain("Hello World".to_string())) - // .singlepart(attachment) - // ).unwrap(); + .multipart( + MultiPart::mixed() + .multipart( + MultiPart::alternative() + .singlepart( + SinglePart::builder() + .header(ContentType::TEXT_PLAIN) + .body(String::from("Hello world")) + ) + .singlepart( + SinglePart::builder() + .header(ContentType::TEXT_HTML) + .body(String::from(HTML)) + ) + ) + .singlepart(attachment) + ).unwrap(); let mailer = SendmailTransport::new();