const
sendGridConfig = {api_user:
'SENDGRID_USERNAME'
, api_key:
'SENDGRID_PASSWORD'
};
const
transporter = nodemailer.
createTransport
(
sgTransport
({auth: sendGridConfig}));
const
sendMail =
pify
(transporter.sendMail);
exports.
handler
function
(event, context) {
const
templateDir = path.
join
(__dirname,
'templates'
, event.template);
const
template =
new
EmailTemplate
(templateDir);
const
render =
pify
(template.render);
template.
render
(event.context)
.
then
(result => {
event.text = result.text;
event.html = result.html;
return
sendMailAsync
(event);
})
.
then
(() => context.
done
(
null
, {message:
'Yaay success'
})))
.
catch
(() => context.
done
(
new
Error
(
'Something went wrong!'
)));
};
HOW TINY?