Skip to content

Instantly share code, notes, and snippets.

@magician11

magician11/config.js

Last active Dec 2, 2017
Embed
What would you like to do?
How to send an email from Node.js using Gmail
module.exports = {
email: {
address: 'youraddress@gmail.com',
password: 'clever-password'
}
};
/*
This module will accept a recipient email address, subject and body of email (in HTML format),
and send it via a Gmail address.
*/
const nodemailer = require('nodemailer');
const config = require('../config');
module.exports = (to, subject, html) => {
return new Promise((resolve, reject) => {
const transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: config.email.address,
pass: config.email.password
}
});
const mailOptions = {
from: config.email.address,
to,
subject,
html
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
reject(error);
} else {
resolve(`Message sent: ${info.response}`);
}
});
});
};
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.