简体   繁体   English

如何在 node.js 上使用邮戳电子邮件?

[英]How to use postmark email on node.js?

I am new to node.js and not able to figure out how to reference js library postmark.js in node.js.我是 node.js 的新手,无法弄清楚如何在 node.js 中引用 js 库 postmark.js。

  var POSTMARK_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
var postmark = require("postmark")(POSTMARK_KEY);

postmark.send({
    "From": from, 
    "To": to, 
    "Subject": subject, 
    "TextBody": emailBody
}, function (err, to) {
if (err) {
    console.log(err);
    return;
}
console.log("Email sent to: %s", to);
});

I tried above code but not sure how to use postmark.js我试过上面的代码,但不知道如何使用 postmark.js

Is there any easy way to have html email functionality using html templates in js?有没有什么简单的方法可以使用 js 中的 html 模板来实现 html 电子邮件功能?

You can use the "HtmlBody field to send html messages through postmark:您可以使用“HtmlBody”字段通过邮戳发送 html 消息:

    postmark.send({
    "From": from, 
    "To": to, 
    "Subject": subject, 
    "TextBody": emailBody,
    "HtmlBody": "<h1>hellow</h1>"
}, function (err, to) {
if (err) {
    console.log(err);
    return;
}
console.log("Email sent to: %s", to);
});

In official document it is described here with example https://postmarkapp.com/developer/integration/official-libraries#node-js在官方文档中,这里描述了示例https://postmarkapp.com/developer/integration/official-libraries#node-js

 // Install with npm npm install postmark --save // Require var postmark = require("postmark"); // Example request var serverToken = "xxxx-xxxxx-xxxx-xxxxx-xxxxxx"; var client = new postmark.ServerClient(serverToken); client.sendEmail({ "From": "sender@example.com", "To": "receiver@example.com", "Subject": "Test", "TextBody": "Hello from Postmark!" });

In order to send html body you can send "HtmlBody": "<h1>some html in string form</h1>" along with "TextBody": "Hello from Postmark!"为了发送 html 正文,您可以发送"HtmlBody": "<h1>some html in string form</h1>""TextBody": "Hello from Postmark!"

like this:像这样:

client.sendEmail({
    "From": "sender@example.com",
    "To": "receiver@example.com",
    "Subject": "Test",
    "TextBody": "Hello from Postmark!"
    "HtmlBody": "<h1>some html in string form</h1>" 
});

which they have described here: https://postmarkapp.com/developer/api/email-api#send-a-single-email他们在这里描述的: https : //postmarkapp.com/developer/api/email-api#send-a-single-email

The method to send email using a template vi API with NodeJs is使用带有 NodeJs 的模板 vi API 发送电子邮件的方法是

sendEmailWithTemplate()

I could not esaily find this in the doc for NodeJs.我无法在 NodeJs 的文档中轻松找到它。

You can find most of the information in the official wiki .您可以在官方 wiki 中找到大部分信息。

To send an email with a template use:要发送带有模板的电子邮件,请使用:

client.sendEmailWithTemplate({
    TemplateId:1234567,
    From: "from@example.com",
    To: "to@example.com",
    TemplateModel: {company: "wildbit"}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM