使用 Handlebars.js 发送包含字母和正文的电子邮件

Send Email with lettre and body with Handlebars.js

这是我的 Rust 车把初始化。没有错误。

  let mut reg = Handlebars::new();
  let order_email_content = reg.render_template("src/emails/order_email.hbs", &serde_json::json!({"data" : email_order.body, "orderNumber": 3333, "amount": 555})).unwrap();

这里是发送邮件的信件:

let host_email = Message::builder()
      .from(config.email.serverEmail.email.parse().unwrap())
      .to(config.email.recipient.parse().unwrap())
      .subject("Rust Order für FlyerandPrint")
      .multipart(
        MultiPart::alternative() // This is composed of two parts.
            .singlepart(
                SinglePart::builder()
                    .header(header::ContentType::TEXT_PLAIN)
                    .body(String::from("Hello from Lettre! A mailer library for Rust")), 
            )
            .singlepart(
                SinglePart::builder()
                    .header(header::ContentType::TEXT_HTML)
                    .body(order_email_content),
            ),
    )
    .unwrap();

这通过了,但收到的电子邮件仅包含路径字符串。

我是 Rust 的新手。谢谢。

问题:我怎样才能包含 handlebars(order_email_content) 中的 html 以在字母正文中使用它?

注意:打印 reg(handlebare 变量)给出:

Handlebars { templates: {}, helpers: ["if", "lt", "raw", "or", "len", "unless", "with", "log", "lookup", "lte", "ne", "and", "not", "gt", "eq", "gte", "each"], decorators: ["inline"], strict_mode: false, dev_mode: false }

但是打印 order_email_content 得到字符串 "src/emails/order_email.hbs"

查看 the handlebar documentation 中的示例,像这样的东西应该可以工作:

let mut reg = Handlebars::new();
reg.register_template_file ("email", "src/emails/order_email.hbs").unwrap();
let order_email_content = reg.render ("email", &serde_json::json!({"data" : email_order.body, "orderNumber": 3333, "amount": 555})).unwrap();

或者:

let mut reg = Handlebars::new();
let order_email_content = reg.render_template (
   include_str!("src/emails/order_email.hbs"),
   &serde_json::json!({"data": email_order.body, "orderNumber": 3333, "amount": 555})).unwrap();