node.js - 邮戳:发送带有模板的电子邮件

标签 node.js email templates postmark

我正在尝试在 Node.js 中发送带有邮戳的模板电子邮件

我在 Postmark App 网站上创建了一个模板。我查看了他们的文档,但找不到发送模板化电子邮件的任何方法。

文档来源:

http://blog.postmarkapp.com/post/125849089273/special-delivery-postmark-templates http://developer.postmarkapp.com/developer-api-templates.html

我尝试了多种方法,包括:

client.emailWithTemplate("jenny@example.com",
   "bob@example.com",<template-id>, {
   "link" : "https://example.com/reset?key=secret",
   "recipient_name" : "Jenny"
});

TypeError: Object # has no method 'emailWithTemplate'

client.sendEmail({
    "TemplateModel" : {
        "customer_name" : "Jenny",
    },
    "TemplateId" : 6882,
    "From": "info@formulastocks.com",
    "To": "lrroberts0122@gmail.com",
}, function(error, success) {
    if(error) {
        console.log(error);
    } else {
        console.log(success);
    }
});

Console Log Error: { status: 422, message: 'A \'TemplateId\' must not be used when sending a non-templated email.', code: 1123 }

谢谢!

最佳答案

我是 node.js 库的当前维护者(也是从事 Postmark 模板的工程师之一)。

原始代码段不起作用的可能原因之一是您使用的可能是旧版本的 Postmark.js。我们在 node.js 包的 1.2.1 版中添加了模板端点功能。

在项目的 package.json 文件中,您应该确保将其更新为使用 1.2.1 或更高版本的 postmark.js 库。如果您一直在使用旧版本的库,您还需要运行 npm update

另请注意,如果您在 Postmark UI 中单击“编辑模板”,然后单击“API 片段”,则该 UI 会提供多种语言(包括 node.js)的完整片段。

如果一切都失败了,请联系支持人员,我们很乐意帮助您解决此问题。

关于node.js - 邮戳:发送带有模板的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32081626/

相关文章:

c++ - 包装一个接受 std::function<double(double)> 的函数,以便传递接受更多参数的函数

c++ - 模板的循环包含

jquery - 在 Web 服务器上安装 Node js

node.js - ES6 方法得到一个空值 "this"并且类变量不可访问

email - 是否有关于 EML 文件格式的 RFC?

python - 使用 Python 发送带有附件的电子邮件的最简单方法是什么?

node.js - 我如何在 React.js 中获取 http header

javascript - 无法将 Brain.JS 导入我的 NodeJS 脚本

c# - 如何忽略发送电子邮件方法并继续执行?

C++ 数组下标运算符模板