2015-08-18 318 views
2

我试图发送一个模板电子邮件邮戳在Node.js的邮戳:发送电子邮件模板

我创建的邮戳应用网站上的模板。我浏览过他们的文档,但无法找到发送模板电子邮件的方法。

文档来源:

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

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

client.emailWithTemplate("[email protected]", 
    "[email protected]",<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": "[email protected]", 
    "To": "[email protected]", 
}, 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 }

谢谢!

回答

4

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

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

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

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

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

+0

哇!没有意识到这很简单。我刚刚在几天前得到了这个,但实际上它是1.0版本 - 现在我已经更新了,它的功能就像一个魅力。 – Lindsay

+1

非常感谢你澄清这一点! :) – Lindsay

+1

@Lindsay我很高兴,谢谢你尝试模板。我们认为他们很棒。 –