Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nodemailer-mailgun-transport

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nodemailer-mailgun-transport - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

6

es5/index.js

@@ -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,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc