diff --git a/Cargo.lock b/Cargo.lock index 4cad696..27839f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1046,7 +1046,7 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" [[package]] name = "lettre" version = "0.10.0-pre" -source = "git+https://github.com/lettre/lettre?rev=88df2a502d537ebfdd4218fb6b9f4168fb0f7943#88df2a502d537ebfdd4218fb6b9f4168fb0f7943" +source = "git+https://github.com/lettre/lettre?rev=2ade0b884630ce1125ffc1011e8604244c1e62e5#2ade0b884630ce1125ffc1011e8604244c1e62e5" dependencies = [ "base64 0.12.0", "bufstream", diff --git a/Cargo.toml b/Cargo.toml index 6a2a783..c4787fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,7 +123,7 @@ rocket = { git = 'https://github.com/SergioBenitez/Rocket', rev = '1010f6a2a88fa rocket_contrib = { git = 'https://github.com/SergioBenitez/Rocket', rev = '1010f6a2a88fac899dec0cd2f642156908038a53' } # Use git version for timeout fix #706 -lettre = { git = 'https://github.com/lettre/lettre', rev = '88df2a502d537ebfdd4218fb6b9f4168fb0f7943' } +lettre = { git = 'https://github.com/lettre/lettre', rev = '2ade0b884630ce1125ffc1011e8604244c1e62e5' } # For favicon extraction from main website data-url = { git = 'https://github.com/servo/rust-url', package="data-url", rev = '7f1bd6ce1c2fde599a757302a843a60e714c5f72' } diff --git a/src/error.rs b/src/error.rs index ecc47d3..5488d6f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -45,8 +45,10 @@ use std::option::NoneError as NoneErr; use std::time::SystemTimeError as TimeErr; use u2f::u2ferror::U2fError as U2fErr; use yubico::yubicoerror::YubicoError as YubiErr; -use lettre::error::Error as LettreErr; + use lettre::address::AddressError as AddrErr; +use lettre::error::Error as LettreErr; +use lettre::message::mime::FromStrError as FromStrErr; use lettre::transport::smtp::error::Error as SmtpErr; #[derive(Serialize)] @@ -75,9 +77,11 @@ make_error! { ReqError(ReqErr): _has_source, _api_error, RegexError(RegexErr): _has_source, _api_error, YubiError(YubiErr): _has_source, _api_error, - LetreError(LettreErr):_has_source, _api_error, - AddressError(AddrErr):_has_source, _api_error, - SmtpError(SmtpErr): _has_source, _api_error, + + LetreError(LettreErr): _has_source, _api_error, + AddressError(AddrErr): _has_source, _api_error, + SmtpError(SmtpErr): _has_source, _api_error, + FromStrError(FromStrErr): _has_source, _api_error, } // This is implemented by hand because NoneError doesn't implement neither Display nor Error diff --git a/src/mail.rs b/src/mail.rs index 9c77b5f..0d14318 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -278,17 +278,25 @@ fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) -> let address = format!("{}@{}", address_split[1], domain_puny); - let html = SinglePart::builder() - .header(header::ContentType("text/html; charset=utf-8".parse().unwrap())) - .header(header::ContentTransferEncoding::QuotedPrintable) - .body(body_html); - - let text = SinglePart::builder() - .header(header::ContentType("text/plain; charset=utf-8".parse().unwrap())) - .header(header::ContentTransferEncoding::QuotedPrintable) - .body(body_text); - - let alternative = MultiPart::alternative().singlepart(text).singlepart(html); + let data = MultiPart::mixed() + .multipart( + MultiPart::alternative() + .singlepart( + SinglePart::quoted_printable() + .header(header::ContentType("text/plain; charset=utf-8".parse()?)) + .body(body_text), + ) + .multipart( + MultiPart::related().singlepart( + SinglePart::quoted_printable() + .header(header::ContentType("text/html; charset=utf-8".parse()?)) + .body(body_html), + ) + // .singlepart(SinglePart::base64() -- Inline files would go here + ), + ) + // .singlepart(SinglePart::base64() -- Attachments would go here + ; let email = Message::builder() .to(Mailbox::new(None, Address::from_str(&address)?)) @@ -297,8 +305,7 @@ fn send_email(address: &str, subject: &str, body_html: &str, body_text: &str) -> Address::from_str(&CONFIG.smtp_from())?, )) .subject(subject) - .multipart(alternative) - .map_err(|e| Error::new("Error building email", e.to_string()))?; + .multipart(data)?; let _ = mailer().send(&email)?; Ok(())