How To Send Mail Using Nodemailer In Node Js

How To Send Mail Using Nodemailer In Node Js

In this article, we would like to inform you how to send email using Nodemailer in node js. here in this example, we are using the express js and nodemailer package for send mail in node js.

Now, here we send mail in node js using SMTP. so you can see below nodemailer example.

Step 1: Create the Application Directory.
First, we will open the command prompt and create the application directory in our directory. for this, you can follow the below command.

Step 2: Install node js packages
In this step, we will create a package.json file in your application directory and paste the below code in this file.

now, you can run below command for install packages.

Step 3: Create Server file
we will create a server.js file in your application directory and paste the below code in this file. here we will load the npm package and set up the mail authentication.

Send Plain Email in Nodejs

If you want to send simple or plain mail then we have to use the text attribute and pass only text.

Send Html Email in Nodejs

If you want to send a mail with HTML then we can also send HTML email in node js. so we have to use HTML attribute and pass HTML code into the HTML attribute.

Send Attachment Email in Nodejs

If you want to send a mail with attachment then we can also send mail with attachment in node js. so we have to use attachment attribute and pass the filename and path into attachments array.

Please follow and like us: