node.jsemailtemplatespostmark

Postmark: Send email with template


I am trying to send a template email with Postmark in Node.js

I created a template on the Postmark App website. I've looked through their documentation, but cannot find any way to go about sending a templated email.

Documentation Sources:

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

I've tried a variety of methods, including:

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 }

Thanks!


Solution

  • I'm the current maintainer of the node.js library (as well as one of the engineers that worked on Postmark Templates).

    One of the possible reasons the original snippet doesn't work is that you could be using an older version of Postmark.js. We added the template endpoint capabilities in version 1.2.1 of the node.js package.

    In the package.json file for your project you should make sure to update it to use version 1.2.1 or greater of the postmark.js library. If you've been using an older version of the library, you'll also need to run npm update

    Also note that if you click "Edit Template" in the Postmark UI, and then "API Snippets," the UI provides a completed snippet for a number of languages (including node.js).

    If all else fails, please contact support and we'll be happy to help you solve this issue.