]> Untitled Git - lemmy.git/commitdiff
send plain-text in email along with html (#2107)
authorRedLobster999 <32234954+RedLobster999@users.noreply.github.com>
Tue, 1 Mar 2022 14:28:18 +0000 (21:28 +0700)
committerGitHub <noreply@github.com>
Tue, 1 Mar 2022 14:28:18 +0000 (14:28 +0000)
* send plain text in email along with html

* format the code using "cargo +nightly fmt"

Co-authored-by: kittiphat-kang <kittiphat.nu@easysunday.com>
Cargo.lock
crates/utils/Cargo.toml
crates/utils/src/email.rs

index 706994b69aad249861e61a042969c29c2e244049..299a18667de3c28431bfb42fd25594c8de061ac7 100644 (file)
@@ -1493,6 +1493,17 @@ dependencies = [
  "regex",
 ]
 
+[[package]]
+name = "html2text"
+version = "0.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a26379dcb715e237b96102a12b505c553e2bffa74bae2e54658748d298660ef1"
+dependencies = [
+ "html5ever",
+ "markup5ever_rcdom",
+ "unicode-width",
+]
+
 [[package]]
 name = "html5ever"
 version = "0.25.1"
@@ -2122,6 +2133,7 @@ dependencies = [
  "doku",
  "encoding",
  "futures",
+ "html2text",
  "http",
  "itertools",
  "jsonwebtoken",
@@ -4265,6 +4277,12 @@ version = "1.8.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
 
+[[package]]
+name = "unicode-width"
+version = "0.1.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
+
 [[package]]
 name = "unicode-xid"
 version = "0.1.0"
index 14d4e7c08bb8278dbe2d2a366bbd66201b19013b..4f9e68f1693639eeacdc9aab9a182ddf1af1bb55 100644 (file)
@@ -45,4 +45,5 @@ webpage = { version = "1.4.0", default-features = false, features = ["serde"] }
 jsonwebtoken = "7.2.0"
 doku = "0.10.2"
 uuid = { version = "0.8.2", features = ["serde", "v4"] }
-encoding = "0.2.33"
\ No newline at end of file
+encoding = "0.2.33"
+html2text = "0.2.1"
\ No newline at end of file
index 69c0fb17b5c523e36448b565418b55f003fc14d1..a52ed405557c9f124d6816a8f217cd7bba491f9b 100644 (file)
@@ -1,4 +1,5 @@
 use crate::{settings::structs::Settings, LemmyError};
+use html2text;
 use lettre::{
   message::{header, Mailbox, MultiPart, SinglePart},
   transport::smtp::{authentication::Credentials, extension::ClientId},
@@ -39,6 +40,9 @@ pub fn send_email(
     )
   };
 
+  // the message length before wrap, 78, is somewhat arbritary but looks good to me
+  let plain_text = html2text::from_read(html.as_bytes(), 78);
+
   let email = Message::builder()
     .from(
       email_config
@@ -58,7 +62,7 @@ pub fn send_email(
           .singlepart(
             SinglePart::builder()
               .header(header::ContentType::TEXT_PLAIN)
-              .body(html.to_string()),
+              .body(plain_text),
           )
           .multipart(
             MultiPart::related().singlepart(