Last active
March 13, 2022 21:07
-
-
Save alexnum/e7a8e77a672a6d9c7647bc40cac4429a to your computer and use it in GitHub Desktop.
Lambda function to send emails using node mailer
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
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