【问题标题】:Sending email using a Transactional Email Template with SendGrid使用带有 SendGrid 的事务性电子邮件模板发送电子邮件
【发布时间】:2016-07-12 18:04:18
【问题描述】:

如何使用带有 SendGrid 的事务性电子邮件模板发送电子邮件。

我正在使用来自 meteorjs 的 email 包,我可以通过

发送简单的电子邮件
  Email.send({
    from: "myemail@gmail.com",
    to: "somebodyelses.email@gmail.com",
    subject: "A sample subject",
    text: "Here is some text."
  });

我也找不到meteorjs包。

【问题讨论】:

    标签: email meteor sendgrid


    【解决方案1】:

    您是否使用正确的主机名和凭据配置了电子邮件包?你可以see an example on the SendGrid blog。一旦您正确配置了服务器并且您可以发送简单的电子邮件,那么您可以添加到Email.headers 一个 X-SMTPAPI 标头。然后你可以use transactional templates via the X-SMTPAPI header

    它看起来像这样:

    Email.send({
      from: "myemail@gmail.com",
      to: "somebodyelses.email@gmail.com",
      subject: "A sample subject",
      text: "Here is some text.",
      headers: {"X-SMTPAPI": '{
          "filters": {
            "templates": {
              "settings": {
                "enable": 1,
                "template_id": "5997fcf6-2b9f-484d-acd5-7e9a99f0dc1f"
              }
            }
          }
        }'
      }
    });
    

    【讨论】:

    • 哇!谢谢!添加headers 就可以了。但是,我以明文形式接收所有内容。意味着图像消失了,文本没有格式化。有什么线索吗?
    • 好的,将"Content-Type" : "text/html" 添加到headers 即可。
    • 我认为这是因为您的html 参数未在Email.send 调用中设置。将其设置为随机的也对我有用。
    • @MarkPazon 即使在添加了 "Content-Type" : "text/html" 之后,它也只为我发送简单的文本电子邮件。 stackoverflow.com/questions/47217847/…有什么帮助吗?
    猜你喜欢
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 2015-11-11
    • 1970-01-01
    • 2016-10-23
    相关资源
    最近更新 更多