Skip to content

Instantly share code, notes, and snippets.

@abernardobr
Created August 20, 2014 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abernardobr/09cfa61b45d9c83f8da7 to your computer and use it in GitHub Desktop.
Save abernardobr/09cfa61b45d9c83f8da7 to your computer and use it in GitHub Desktop.
NodeMailler with Mandrill
var _ = require("lodash");
var emailServerConfig = {
type: "Mantrill",
otions: {
auth: {
user: "XXX", // your email that you used to register at Mandrill
pass: "XXXXX" // At the user panel you create a password to use with your login
}
};
var Nodemailer = require("nodemailer");
var internals = {
transport: null
};
internals.createTransport = function() {
if(internals.transport == null)
internals.transport = Nodemailer.createTransport(emailServerConfig.type, emailServerConfig.options);
return !_.isFunction(internals.transport);
}
internals.sendMail = function(from, to, subject, text, isHTML, cb) {
if(!internals.createTransport()) {
console.log("Error creating email transport!");
cb(null, "");
return;
}
if(isHTML)
internals.transport.sendMail({
from: from, // sender address
to: to, // comma separated list of receivers
subject: subject, // Subject line
html: text // html body
}, function(err, response){
if(err){
cb(err);
} else{
cb(err, response.message);
}
});
else
internals.transport.sendMail({
from: from, // sender address
to: to, // comma separated list of receivers
subject: subject, // Subject line
text: text // plaintext body
}, function(err, response){
if(err){
cb(err);
} else{
cb(err, response.message);
}
});
}
module.exports = {
sendMail: internals.sendMail
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment