Send email using Node Js

Send email using Node Js

Original post - Click Here

Nodemailer Package is used to send mail easily from your server. To download and use this module we need to install it from NPM –

npm install nodemailer

Now we are ready to send email –

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: 'youremail@gmail.com',
    pass: 'yourpassword'
  }
});

var mailOptions = {
  from: 'youremail@gmail.com',
  to: 'myfriend@yahoo.com',
  subject: 'Sending Email using Node.js',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});

We need to replace email and password with valid credentials to start sending the emails.

To view or add a comment, sign in

More articles by Harendra Kumar Kanojiya

  • 10 Mini Python Projects That You Should Try in 2022

    Originally published here To call oneself a programmer, you must know the grammar of code. A competent programmer…

  • 20 Python Snippets You Should Learn in 2021

    Python is one of the most popular languages used by many in Data Science, machine learning, web development, scripting…

    1 Comment
  • Top udemy course to learn react js for beginners

    Hello Guys, udemy is a very popular website for online video courses and provides tons of courses in almost every…

  • Python 3 quick start guide

    Python 3 is a truly versatile programming language, loved both by web developers, data scientists and software…

  • Top 10 projects for beginner programmers

    Top 10 projects for beginner programmers 2021–08–19 10:18:00 Any developer will tell you: coding can be very…

Insights from the community

Others also viewed

Explore topics