Reputation: 633
I am new to node.js and not able to figure out how to reference js library postmark.js in node.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
Is there any easy way to have html email functionality using html templates in js?
Upvotes: 2
Views: 3018
Reputation: 4757
You can find most of the information in the official wiki.
To send an email with a template use:
client.sendEmailWithTemplate({
TemplateId:1234567,
From: "[email protected]",
To: "[email protected]",
TemplateModel: {company: "wildbit"}
});
Upvotes: 1
Reputation: 333
The method to send email using a template vi API with NodeJs is
sendEmailWithTemplate()
I could not esaily find this in the doc for NodeJs.
Upvotes: 1
Reputation: 3435
In official document it is described here with example 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": "[email protected]", "To": "[email protected]", "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!"
like this:
client.sendEmail({
"From": "[email protected]",
"To": "[email protected]",
"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
Upvotes: 1
Reputation: 1082
You can use the "HtmlBody field to send html messages through postmark:
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);
});
Upvotes: 2