Sparkpost transport for Nodemailer
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
examples linting Jul 16, 2018

Sign up for a SparkPost account and visit our Developer Hub for more resources.

SparkPost transport for Nodemailer


Build Status NPM version



npm install nodemailer-sparkpost-transport

Create a Nodemailer transport object

var nodemailer = require('nodemailer');
var sparkPostTransport = require('nodemailer-sparkpost-transport');
var transporter = nodemailer.createTransport(sparkPostTransport(options));


  • options defines connection default transmission properties
    • sparkPostApiKey - SparkPost API Key. If not provided, it will use the SPARKPOST_API_KEY env var.
    • endpoint - The endpoint to use for the SparkPost API requests. If you have a SparkPost EU account, set this to (optional)
    • campaign_id - Name of the campaign (optional)
    • metadata - Transmission level metadata containing key/value pairs (optional)
    • options - JSON object in which transmission options are defined (optional)
    • substitution_data - Key/value pairs that are provided to the substitution engine (optional)

For more information, see the SparkPost API Documentation for Transmissions

Send a message

  from: '',
  to: '',
  subject: 'Very important stuff',
  text: 'Plain text',
  html: 'Rich taggery'
}, function(err, info) {
  if (err) {
    console.log('Error: ' + err);
  } else {
    console.log('Success: ' + info);

Read more about Nodemailer's sendMail() method here.

Additional Options

The SparkPost Nodemailer transport also supports a few SparkPost-specific sendMail() options in both the transport constructor and the 'sendMail()` method.

Note: sendMail() options override their constructor counterparts:

  • options
    • campaign_id - Overrides for constructor option
    • metadata - Override for constructor option
    • options - Override for constructor option
    • substitution_data - Override for constructor option