nodemailer-mailgun-transport
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -105,3 +105,5 @@ var __assign = (this && this.__assign) || function () { | ||
case 0: | ||
if (!template || !template.name || !template.engine) { | ||
if (!template || typeof template === "string" || !template.name || !template.engine) { | ||
// either there's no template or the caller is requesting a mailgun template | ||
// so let everything through unaltered | ||
return [2 /*return*/, {}]; | ||
@@ -195,3 +197,3 @@ } | ||
var messages = mailgun({ | ||
apiKey: options.auth.api_key, | ||
apiKey: options.auth.api_key || options.auth.apiKey, | ||
domain: options.auth.domain || "", | ||
@@ -198,0 +200,0 @@ proxy: options.proxy || false, |
@@ -5,3 +5,3 @@ { | ||
"description": "A transport module to use with nodemailer to leverage Mailgun's REST API", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -118,6 +118,27 @@ nodemailer-mailgun-transport | ||
``` | ||
## Now with Consolidate.js templates | ||
## Now with Consolidate.js templates, and also compatible with mailgun's own templates | ||
If you pass a "template" key an object that contains a "name" key, an "engine" key and, optionally, a "context" object, you can use Handlebars templates to generate the HTML for your message. Like so: | ||
This package has two options for templating - one is to allow mailgun's templating engine to process the template, and the other is to use templates in your own codebase using any templating engine supported by consolidate.js. | ||
To use mailgun's templating engine (and allow templates to iterate independent of your codebase), simply pass the template name to the `template` key, and the template variables as a stringified JSON to the `h:X-Mailgun-Variables` key. Here's an example: | ||
 | ||
```javascript | ||
nodemailerMailgun.sendMail({ | ||
from: 'myemail@example.com', | ||
to: 'recipient@domain.com', // An array if you have multiple recipients. | ||
subject: 'Hey you, awesome!', | ||
template: 'boss_door', | ||
'h:X-Mailgun-Variables': JSON.stringify({key:'boss'}) | ||
}, (err, info) => { | ||
if (err) { | ||
console.log(`Error: ${err}`); | ||
} | ||
else { | ||
console.log(`Response: ${info}`); | ||
} | ||
}); | ||
``` | ||
To use consolidate.js templates locally, give the `template` key an object instead that contains a `name` key, an `engine` key and, optionally, a `context` object. For example, you can use Handlebars templates to generate the HTML for your message like so: | ||
```js | ||
@@ -124,0 +145,0 @@ const handlebars = require('handlebars'); |
@@ -53,3 +53,5 @@ const mailgun = require("mailgun-js"); | ||
const renderTemplate = async template => { | ||
if (!template || !template.name || !template.engine) { | ||
if (!template || typeof template === "string" || !template.name || !template.engine) { | ||
// either there's no template or the caller is requesting a mailgun template | ||
// so let everything through unaltered | ||
return {}; | ||
@@ -136,3 +138,3 @@ } | ||
const messages = mailgun({ | ||
apiKey: options.auth.api_key, | ||
apiKey: options.auth.api_key || options.auth.apiKey, | ||
domain: options.auth.domain || "", | ||
@@ -139,0 +141,0 @@ proxy: options.proxy || false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23339
368
210