Skip to content

Instantly share code, notes, and snippets.

@alexnum
Last active March 13, 2022 21:07
Show Gist options
  • Save alexnum/e7a8e77a672a6d9c7647bc40cac4429a to your computer and use it in GitHub Desktop.
Save alexnum/e7a8e77a672a6d9c7647bc40cac4429a to your computer and use it in GitHub Desktop.
Lambda function to send emails using node mailer
require('dotenv').config()
var nodemailer = require('nodemailer');
const {EMAIL_SERVICE, EMAIL, EMAIL_PASSWORD, PORT} = process.env;
var transporter = nodemailer.createTransport({
service: EMAIL_SERVICE,
auth: {
user: EMAIL,
pass: EMAIL_PASSWORD
}
});
exports.handler = (event) => {
return new Promise((resolve, reject)=>{
var mailOptions = {from: EMAIL, ...event};
console.log('Sending confirmation email to:', event.to);
transporter.sendMail(mailOptions, function(error, info){
if (error) {
reject(error);
} else {
resolve({status: 'OK'});
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment