Created
June 28, 2016 17:21
-
-
Save ecaron/97bccfaed1f44196599406b362653f40 to your computer and use it in GitHub Desktop.
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
| // Code for V2 | |
| var sendgrid = require('sendgrid')(sendgrid_api_key); | |
| sendgrid.send({ | |
| to: '[email protected]', | |
| from: '[email protected]', | |
| subject: 'Hello World', | |
| text: 'My first email through SendGrid.' | |
| }, function(err, json) { | |
| if (err) { return console.error(err); } | |
| console.log(json); | |
| }); | |
| // Code for V3 | |
| 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/plain", "some text here") | |
| var mail = new helper.Mail(from_email, subject, to_email, content) | |
| var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY) | |
| var requestBody = mail.toJSON() | |
| var request = sg.emptyRequest() | |
| request.method = 'POST' | |
| request.path = '/v3/mail/send' | |
| request.body = requestBody | |
| sg.API(request, function (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