Skip to content

Instantly share code, notes, and snippets.

@shamsher31
Created July 7, 2015 04:41
Show Gist options
  • Save shamsher31/f49fd94ee5227bcfcc45 to your computer and use it in GitHub Desktop.
Save shamsher31/f49fd94ee5227bcfcc45 to your computer and use it in GitHub Desktop.
NodeJS Send Email using SendGrid
var Promise = require('bluebird'),
nodemailer = Promise.promisifyAll(require('nodemailer')),
sendGridTransport = require('nodemailer-sendgrid-transport');
var options = {
auth: {
api_user: process.env.SENDGRID_USERNAME,
api_key: process.env.SENDGRID_PASSWORD
}
}
var transport = Promise.promisifyAll(nodemailer.createTransport(sendGridTransport(options)));
function SendReport() {
var mailOptions = {
from: FROM, // sender address
to: TO, // list of receivers
subject: subject, // Email subject line,
html: BODY, // Email body
attachments: [
{
filename: fileName + '.csv',
content: res,
contentType: 'text/csv'
}
]
};
return transport.sendMailAsync(mailOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment