Skip to content

Instantly share code, notes, and snippets.

@carlok carlok/hapi-awsses.js
Last active Apr 20, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.