Skip to content

Instantly share code, notes, and snippets.

@slonoed
Created October 6, 2016 08:39
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 slonoed/60ee3c0fdf46920de190a090fead3ab8 to your computer and use it in GitHub Desktop.
Save slonoed/60ee3c0fdf46920de190a090fead3ab8 to your computer and use it in GitHub Desktop.
send email via sendgrid
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('e@slonoed.net');
var to_email = new helper.Email('guru.veronika@gmail.com');
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