Learn Simpli

Free Online Tutorial For Programmers, Contains a Solution For Question in Programming. Quizzes and Practice / Company / Test interview Questions.

Sending mails in nodeJS

The npm provides a pretty package to send the emails
1. Using nodemailer
  1. The Nodemailer module makes it easy to send emails from the nodejs application
  2. Install using the command, npm install nodemailer
  var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'test@test.com',
    pass: 'password'
  }
});
var config = {
  from: 'test@test.com',
  to: 'test2@test.com',
  subject: 'Test mail from sendmailer',
  text: 'Hello world!'
};
transporter.sendMail(config, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent');
  }
});