diff --git a/src/mail.rs b/src/mail.rs index 5cc126588d..6e293eafb4 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -4,7 +4,7 @@ use chrono::NaiveDateTime; use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; use lettre::{ - message::{Mailbox, Message, MultiPart}, + message::{Attachment, Body, Mailbox, Message, MultiPart, SinglePart}, transport::smtp::authentication::{Credentials, Mechanism as SmtpAuthMechanism}, transport::smtp::client::{Tls, TlsParameters}, transport::smtp::extension::ClientId, @@ -467,13 +467,30 @@ pub async fn send_test(address: &str) -> EmptyResult { } async fn send_email(address: &str, subject: &str, body_html: String, body_text: String) -> EmptyResult { + const LOGO_GRAY: &[u8] = include_bytes!("static/images/logo-gray.png"); + const MAIL_GITHUB: &[u8] = include_bytes!("static/images/mail-github.png"); + let logo_gray_body = Body::new(LOGO_GRAY.to_vec()); + let mail_github_body = Body::new(MAIL_GITHUB.to_vec()); let smtp_from = &CONFIG.smtp_from(); let email = Message::builder() .message_id(Some(format!("<{}@{}>", crate::util::get_uuid(), smtp_from.split('@').collect::>()[1]))) .to(Mailbox::new(None, Address::from_str(address)?)) .from(Mailbox::new(Some(CONFIG.smtp_from_name()), Address::from_str(smtp_from)?)) .subject(subject) - .multipart(MultiPart::alternative_plain_html(body_text, body_html))?; + .multipart( + MultiPart::alternative().singlepart(SinglePart::plain(body_text)).multipart( + MultiPart::related() + .singlepart(SinglePart::html(body_html)) + .singlepart( + Attachment::new_inline(String::from("logo-gray")) + .body(logo_gray_body, "image/png".parse().unwrap()), + ) + .singlepart( + Attachment::new_inline(String::from("github-logo")) + .body(mail_github_body, "image/png".parse().unwrap()), + ), + ), + )?; match mailer().send(email).await { Ok(_) => Ok(()), diff --git a/src/static/templates/email/email_footer.hbs b/src/static/templates/email/email_footer.hbs index 33177317fa..924e83d392 100644 --- a/src/static/templates/email/email_footer.hbs +++ b/src/static/templates/email/email_footer.hbs @@ -10,7 +10,7 @@ - +
GitHubGitHub
diff --git a/src/static/templates/email/email_header.hbs b/src/static/templates/email/email_header.hbs index a1e7cc27e3..4e826466d6 100644 --- a/src/static/templates/email/email_header.hbs +++ b/src/static/templates/email/email_header.hbs @@ -81,7 +81,7 @@