Lin*_*say 2 email templates node.js postmark
我正在尝试在 Node.js 中发送带有 Postmark 的模板电子邮件
我在 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"
});
Run Code Online (Sandbox Code Playgroud)
类型错误:对象 # 没有方法“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);
}
});
Run Code Online (Sandbox Code Playgroud)
控制台日志错误:{ 状态:422,消息:'A \'TemplateId\' 在发送非模板化电子邮件时不得使用。',代码:1123 }
谢谢!
我是 node.js 库的当前维护者(也是从事 Postmark Templates 的工程师之一)。
原始代码段不起作用的可能原因之一是您可能使用的是较旧版本的 Postmark.js。我们在 node.js 包的 1.2.1 版中添加了模板端点功能。
在项目的 package.json 文件中,您应该确保将其更新为使用 1.2.1 或更高版本的 postmark.js 库。如果您一直在使用旧版本的库,则还需要运行npm update
另请注意,如果您在 Postmark UI 中单击“编辑模板”,然后单击“API Snippets”,则 UI 会为多种语言(包括 node.js)提供完整的代码段。
如果所有其他方法都失败,请联系支持人员,我们将很乐意帮助您解决此问题。