Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- const Mailer = require('nodemailer');
- const Ses = require('nodemailer-ses-transport');
- exports.register = function (server, options, next) {
- const sendTextMailPrm = function (to, subject, body) {
- const mailOptions = {
- from: options.from,
- to: to,
- subject: subject,
- text: body
- //html: '....'
- };
- const transporter = Mailer.createTransport(Ses({
- accessKeyId: options.username,
- secretAccessKey: options.password,
- region: options.region,
- rateLimit: 5 // do not send more than 5 messages in a second
- }));
- let mailPromise = new Promise((resolve, reject) => {
- transporter.sendMail(mailOptions, function (error, info) {
- if (error) {
- reject(error);
- }
- resolve(info);
- });
- });
- return mailPromise
- .then((success) => {
- console.log('mailPromise success', success);
- return success;
- })
- .catch(
- (failure) => {
- console.log('mailPromise success', failure);
- return failure;
- });
- };
- server.expose({
- sendTextMailPrm: sendTextMailPrm
- });
- next();
- };
- exports.register.attributes = {
- name: 'sendgrid'
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement