Nodejs email

To send the email in Nodejs through nodemailer package.
Firstly installed nodemailer package.


npm install --save nodemailer

Now open the URL https://mailtrap.io/

create the signup

get the username and password

Now, create the email.js file and write the below code


var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({
  host: 'smtp.mailtrap.io',
  port: 2525,
  auth: {
     user: 'put_your_username_here', //put_your_username_here
     pass: 'put_your_password_here' //put_your_password_here
  }
});

var mailOptions = {
  from: 'fromemail@abc.com',
  to: 'toemail@abc.com',
  subject: 'Test Email',
  html: '

HTML body text data

' }; transporter.sendMail(mailOptions, function(error, info){ if (error) { console.log(error); } else { console.log('Email sent: ' + info.response); } });
Output:-
Email sent: 250 2.0.0 Ok: queued

Check the send email content in mailtrap inbox