Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. 'use strict';
  2. const Mailer = require('nodemailer');
  3. const Ses = require('nodemailer-ses-transport');
  4.  
  5. exports.register = function (server, options, next) {
  6.  
  7. const sendTextMailPrm = function (to, subject, body) {
  8.  
  9. const mailOptions = {
  10. from: options.from,
  11. to: to,
  12. subject: subject,
  13. text: body
  14. //html: '....'
  15. };
  16.  
  17. const transporter = Mailer.createTransport(Ses({
  18. accessKeyId: options.username,
  19. secretAccessKey: options.password,
  20. region: options.region,
  21. rateLimit: 5 // do not send more than 5 messages in a second
  22. }));
  23.  
  24. let mailPromise = new Promise((resolve, reject) => {
  25.  
  26. transporter.sendMail(mailOptions, function (error, info) {
  27. if (error) {
  28. reject(error);
  29. }
  30.  
  31. resolve(info);
  32. });
  33. });
  34.  
  35. return mailPromise
  36. .then((success) => {
  37.  
  38. console.log('mailPromise success', success);
  39. return success;
  40. })
  41. .catch(
  42. (failure) => {
  43.  
  44. console.log('mailPromise success', failure);
  45. return failure;
  46. });
  47. };
  48.  
  49. server.expose({
  50. sendTextMailPrm: sendTextMailPrm
  51. });
  52.  
  53. next();
  54. };
  55.  
  56. exports.register.attributes = {
  57. name: 'sendgrid'
  58. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement