Created
July 7, 2015 04:41
-
-
Save shamsher31/f49fd94ee5227bcfcc45 to your computer and use it in GitHub Desktop.
NodeJS Send Email using SendGrid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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