Last active
April 20, 2017 15:52
-
-
Save carlok/72f19878a503fedd22a0cc92d604c2a2 to your computer and use it in GitHub Desktop.
Hapi Plugin AWS SES (Nodemailer Promosificated)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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