Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // Code for V2
  2. var sendgrid = require('sendgrid')(sendgrid_api_key);
  3. sendgrid.send({
  4. to: 'example@example.com',
  5. from: 'other@example.com',
  6. subject: 'Hello World',
  7. text: 'My first email through SendGrid.'
  8. }, function(err, json) {
  9. if (err) { return console.error(err); }
  10. console.log(json);
  11. });
  12.  
  13. // Code for V3
  14. var helper = require('sendgrid').mail
  15. var from_email = new helper.Email("test@example.com")
  16. var to_email = new helper.Email("test@example.com")
  17. var subject = "Hello World from the SendGrid Node.js Library"
  18. var content = new helper.Content("text/plain", "some text here")
  19. var mail = new helper.Mail(from_email, subject, to_email, content)
  20. var sg = require('sendgrid').SendGrid(process.env.SENDGRID_API_KEY)
  21. var requestBody = mail.toJSON()
  22. var request = sg.emptyRequest()
  23. request.method = 'POST'
  24. request.path = '/v3/mail/send'
  25. request.body = requestBody
  26. sg.API(request, function (response) {
  27. console.log(response.statusCode)
  28. console.log(response.body)
  29. console.log(response.headers)
  30. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement