Guest User

Untitled

a guest
Jun 18th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. 'use latest';
  2. import sendgrid from 'sendgrid';
  3. const helper = sendgrid.mail;
  4. /**
  5. * @param context {WebtaskContext}
  6. */
  7. module.exports = (context, cb) => {
  8. // POST JSON with at least the following properties.
  9. const { from_email, to_email, subject, content } = context.body;
  10. const mail = new helper.Mail(
  11. new helper.Email(from_email),
  12. subject,
  13. new helper.Email(to_email),
  14. new helper.Content('text/plain', content)
  15. );
  16. const sg = sendgrid(context.secrets.SENDGRID_API_KEY);
  17. const request = sg.emptyRequest({
  18. method: 'POST',
  19. path: '/v3/mail/send',
  20. body: mail.toJSON()
  21. });
  22. sg.API(request)
  23. .then(response => cb(null, response))
  24. .catch(cb);
  25. };
Add Comment
Please, Sign In to add comment