邮戳:发送带有模板的电子邮件

Postmark: Send email with template

我正尝试在 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

另请注意,如果您点击邮戳 UI 中的 "Edit Template",然后点击 "API Snippets,",UI 会提供多种语言的完整片段(包括 node.js).

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