Mandrill transport for Nodemailer
Clone or download
Devin Torres
Devin Torres Merge pull request #44 from Rebelmail/david-dm
Add David DM badges
Latest commit fd55199 Aug 19, 2016
Permalink
Failed to load latest commit information.
lib Use addressparser Feb 19, 2016
test Support for mandrill templates Feb 10, 2016
.editorconfig Add .editorconfig Mar 30, 2015
.gitignore Upgrade dependencies Aug 12, 2016
.jshintrc Initial commit Mar 27, 2015
.travis.yml Upgrade dependencies Aug 12, 2016
LICENSE Upgrade dependencies Aug 12, 2016
README.md Add David DM badges Aug 19, 2016
index.js Initial commit Mar 27, 2015
package.json 1.2.0 Aug 12, 2016

README.md

nodemailer-mandrill-transport

A Mandrill transport for Nodemailer.

Build Status Coverage Status npm version Dependency Status devDependency Status

Example

'use strict';

var nodemailer = require('nodemailer');

var mandrillTransport = require('nodemailer-mandrill-transport');

var transport = nodemailer.createTransport(mandrillTransport({
  auth: {
    apiKey: 'key'
  }
}));

transport.sendMail({
  from: 'sender@example.com',
  to: 'user@example.com',
  subject: 'Hello',
  html: '<p>How are you?</p>'
}, function(err, info) {
  if (err) {
    console.error(err);
  } else {
    console.log(info);
  }
});

Using Mandrill API options

It is possible to use any Messages Send Mandrill API option by passing it into the mandrillOptions option. These will be deeply merged over the API call this transport builds for you. For example, this transport enables the async option by default. To disable this,

transport.sendMail({
  mandrillOptions: {
    async: false
  }
}, /* ... */);

Sending Images to Mandrill

To send images as attachments:

transport.sendMail({
  mandrillOptions: {
    images: [
      'type': 'image/png',
      'name': 'IMAGECID',
      'content': 'ZXhhbXBsZSBmaWxl',
    ],
  }
}, /* ... */);

name: image cid:

Reference your attached image in your HTML:

<img src="IMAGECID">

Make sure to use unique cids for your images!

content: a base64 representation of your image.

var fs = require('fs');
var imgBuff = fs.readFileSync('path/to/file');

imgBuff.toString('base64');

Using Mandrill Templates

To send email using templates stored on Mandrill:

transport.sendMail({
  mandrillOptions: {
    template_name: 'MANDRILL_TEMPLATE_SLUG'
  }
}, /* ... */);