Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code for V2
- var sendgrid = require('sendgrid')(sendgrid_api_key);
- sendgrid.send({
- to: 'example@example.com',
- from: 'other@example.com',
- 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("test@example.com")
- var to_email = new helper.Email("test@example.com")
- 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)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement