How To Send email In NodeJs

How To Send email In NodeJs

In this post we will give you information about How To Send email In NodeJs. Hear we will give you detail about How To Send email In NodeJsAnd how to use it also give you demo for it if it is necessary.

Today, Laravel share with you how to send mail in nodejs. in current position nodejs is more and more use. many things we have done with nodejs without write huge .


In this tutorials we are share with you email sending in nodejs. becasue in any application we must be required a mail sending functionality.

See also  How to generate route with query string parameter in Laravel 5?


We are write here very simple for mail sending in nodejs. you can mail send in nodejs using nodemailer


Step : 1 Install nodemailer


We are first need to install nodemailer package for mail sending in nodejs. run followign command for install it.




npm install nodemailer@0.7.1



Step : 2 Create mail.js file



No create mail.js file in your project root directory and simple put following into it.




var nodemailer = require('nodemailer');

// Create a SMTP transport object
var transport = nodemailer.createTransport("SMTP", {
        service: 'Gmail',
        auth: {
            user: "online@gmail.com",
            pass: "online"
        }
    });

console.log('SMTP Configured');

// Message object
var message = {

    // sender info
    from: 'Sender Name <online@gmail.com>s',

    // Comma separated list of recipients
    to: '"Receiver Name" <online@gmail.com>s',

    // Subject of the message
    subject: 'How to send mail in nodejs ✔', 

    // plaintext body
    text: 'Hello, everyone!',

    // HTML body
    html:'s<b>sLook this</b>s  <img src=""/>s</p>s'+
         'sHere i am send my picture attachment:<br/>s</p>s'
};

console.log('Sending Mail');
transport.sendMail(message, function(error){
  if(error){
      console.log('Error occured');
      console.log(error.message);
      return;
  }
  console.log('Message sent successfully!');

  // if you don't want to use this transport object anymore, uncomment following line
  //transport.close(); // close the connection pool
});



See also  Laravel 5 manual pagination with array example

Now we are ready to run our example so run bellow command ro quick run:




node mail.js



If you face any problem then please write a comment or give some suggestions for improvement. Thanks…

Hope this and post will helped you for implement How To Send email In NodeJs. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs

See also  Laravel 5 email verification with activation code example

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

45  +    =  53

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US