Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Last active December 10, 2016 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PandaWhoCodes/4bce68c3e5950916320b5bbcca0cf6b8 to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/4bce68c3e5950916320b5bbcca0cf6b8 to your computer and use it in GitHub Desktop.
Send mail using Gmail in node.js using nodemailer
'use strict';
var nodemailer = require('nodemailer');
//configure nodemailer
// visit: https://nodemailer.com/
// For other types of transports (Amazon SES, Sendgrid,mailchimp...) see https://nodemailer.com/2-0-0-beta/setup-transporter/
var mailTransport = nodemailer.createTransport('smtps://<user>%40gmail.com:<password>@smtp.gmail.com');
function senEmail(email) {
var mailOptions = {
from: '"Ashish Cherian" <noreply@yourdomain.com>',
to: email, // Email is variable that stores the email address
subject: 'Node Js stuff',
text: 'What ever text you want to make in the email. Or insert an '
};
return mailTransport.sendMail(mailOptions).then(function() {
console.log('New star email notification sent to: ' + email);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment