Node JS - Node js send an email - Node - Node JS tutorial - webnode




How to Send an Email in Node.js ?

  • Now you are ready to send emails from your server.
  • Use the username and password from your selected email provider to send an email.

node.js sent a email

The Node mailer Module:

  • The Nodemailer module can be downloaded and installed using npm:
C:\Users\Your Namenpm install nodemailer
  • After you have downloaded the Nodemailer module, you can include the module in any application:
var nodemailer = require('nodemailer');

Example

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: '[email protected]',
    pass: 'yourpassword'
  }
});

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js',
  text: 'Wikitechy is an enhanced tutorials'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});
  • And that's it! Now your server is able to send emails.
Related nodejs article tags - node js - node js tutorial - node js examples

Multiple Receivers:

  • To send an email to more than one receiver, add them to the "to" property of the mailOptions object, separated by a comma:

Example:

  • Send email to more than one address:
var mailOptions = {
  from: '[email protected]',
  to: '[email protected][email protected]',
  subject: 'Sending Email using Node.js',
  text: 'Wikitechy is an enhanced tutorials'
}

Send HTML:

  • To send HTML formatted text in your email, use the "html" property instead of the "text" property:

Example:

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js',
  html: '<h1>Welcome to wikitechy</h1><p>Wikitechy is an enhanced tutorials</p>'
}


This wikitechy technological portal provides you whole lot of information related to the topics such as mongodb tutorial , what is node js , express js tutorial , node js tutorial pdf , learn node js , node js tutorial for beginners , node js tutorial w3schools , node js express , javascript for beginners , node js express tutorial , node js tutorial point , node js book , node js server , note js , node js mongodb , what is node js used for , why node js , node tutorial , node js basics , tutorialspoint node js , node express , node js sample application , nodeschool , node js for beginners , express tutorial , node js application , use of node js , npm tutorial , node js org , node js training , node js online training , node js tutorial beginner , how to use node js , node js hello world , express node js , node js mongodb tutorial , nodejs http , why use node js

Related Searches to Node.js Send an Email