nodemailer-sparkpost-transport
SparkPost transport for Nodemailer
Usage
Install with npm
npm install nodemailer-sparkpost-transport
Require to your script
var nodemailer = require('nodemailer');
var sparkPostTransport = require('nodemailer-sparkpost-transport');
Create a Nodemailer transport object
var transporter = nodemailer.createTransport(sparkPostTransport(options))
Where
- options defines connection and message data
sparkPostApiKey
- SparkPost API Key. If not provided, it will use the SPARKPOST_API_KEY
env var.campaign_id
- Name of the campaigncontent
- Content that will be used to construct a messagemetadata
- Transmission level metadata containing key/value pairsoptions
- JSON object in which transmission options are definedsubstitution_data
- Key/value pairs that are provided to the substitution engine
For more information, see the SparkPost API Documentation for Transmissions
Send a message
transport.sendMail(options, function(err, info) {});
Where
- options defines connection and message data
recipients
- Inline recipient objects or object containing stored recipient list ID. See SparkPost API Documentation for Recipient Lists for more information.campaign_id
- Override for option abovecontent
- Override for option abovemetadata
- Override for option aboveoptions
- Override for option abovesubstitution_data
- Override for option above
Example
'use strict';
var nodemailer = require('nodemailer');
var sparkPostTransport = require('nodemailer-sparkpost-transport');
var transporter = nodemailer.createTransport(sparkPostTransport({
"sparkPostApiKey": "<YOUR_API_KEY>",
"options": {
"open_tracking": true,
"click_tracking": true,
"transactional": true
},
"campaign_id": "Nodemailer Default",
"metadata": {
"some_useful_metadata": "testing_sparkpost"
},
"substitution_data": {
"sender": "YOUR NAME",
"fullName": "YOUR NAME",
"productName": "The coolest product ever",
"sparkpostSupportEmail": "support@sparkpost.com",
"sparkpostSupportPhone": "123-456-7890"
},
"content": {
"template_id": "ADD YOUR TEMPLATE ID HERE"
}
}));
transporter.sendMail({
"recipients": [
{
"address": {
"email": "CHANGE TO YOUR TARGET TEST EMAIL",
"name": "CHANGE TO YOUR RECIPIENT NAME"
}
}
]
}, function(err, info) {
if (err) {
console.error(err);
} else {
console.log(info);
}
});