Skip to content

Instantly share code, notes, and snippets.

@carlok
Last active April 20, 2017 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlok/72f19878a503fedd22a0cc92d604c2a2 to your computer and use it in GitHub Desktop.
Save carlok/72f19878a503fedd22a0cc92d604c2a2 to your computer and use it in GitHub Desktop.
Hapi Plugin AWS SES (Nodemailer Promosificated)
'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, (error, info) => {
if (error) {
return reject(error);
}
resolve(info);
});
});
return mailPromise
// catch on the other side
.then((success) => {
console.log('mailPromise success', success);
return success;
});
};
server.expose({
sendTextMailPrm: sendTextMailPrm
});
next();
};
exports.register.attributes = {
name: 'awsses'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment