Created
October 6, 2016 08:39
-
-
Save slonoed/60ee3c0fdf46920de190a090fead3ab8 to your computer and use it in GitHub Desktop.
send email via sendgrid
This file contains hidden or 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
const KEY = "SENDGRID KEY HERE"; | |
const fs = require('fs'); | |
const html = fs.readFileSync('./index-1.html', 'utf8'); | |
var helper = require('sendgrid').mail; | |
var from_email = new helper.Email('[email protected]'); | |
var to_email = new helper.Email('[email protected]'); | |
var subject = 'Hello World from the SendGrid Node.js Library!'; | |
var content = new helper.Content('text/html',html); | |
var mail = new helper.Mail(from_email, subject, to_email, content); | |
var sg = require('sendgrid')(KEY); | |
var request = sg.emptyRequest({ | |
method: 'POST', | |
path: '/v3/mail/send', | |
body: mail.toJSON(), | |
}); | |
sg.API(request, function(error, response) { | |
console.log(response.statusCode); | |
console.log(response.body); | |
console.log(response.headers); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment