Sending an Email with Nodemailer in Node.js | Watch Hindi Tutorial on Nodemailer Email Sending

Posted by


Nodemailer is a popular Node.js module that allows you to send emails from your Node.js application. In this tutorial, we will learn how to send an email using Nodemailer in Node.js.

Step 1: Install Nodemailer
First, you need to install Nodemailer in your Node.js application. You can do this by running the following command in your terminal:

npm install nodemailer

Step 2: Set up your email configuration
Next, you need to set up your email configuration. You will need to provide your email service provider’s SMTP (Simple Mail Transfer Protocol) server details, username, and password. In this tutorial, we will use Gmail as our email service provider.

const nodemailer = require('nodemailer');

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'your_email@gmail.com',
        pass: 'your_email_password'
    }
});

Step 3: Create and send the email
Now, you can create an email message and send it using the sendMail method of the transporter object.

// setup email data with unicode symbols
let mailOptions = {
    from: 'your_email@gmail.com', // sender address
    to: 'recipient_email@example.com', // list of receivers
    subject: 'Hello ✔', // Subject line
    text: 'Hello world?', // plain text body
    html: '<b>Hello world?</b>' // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
    if (error) {
        return console.log(error);
    }
    console.log('Message %s sent: %s', info.messageId, info.response);
});

Step 4: Test your email sending functionality
You can now run your Node.js application and test if the email is being sent successfully using Nodemailer.

node app.js

If everything is set up correctly, you should see a message in the console indicating that the email has been sent successfully.

In this tutorial, we learned how to send an email using Nodemailer in Node.js. Nodemailer is a powerful module that allows you to send emails from your Node.js application easily. You can customize your email message further by setting various options such as subject, text, and html body.

I hope this tutorial was helpful in guiding you through the process of sending an email using Nodemailer in Node.js. If you have any questions or run into any issues, feel free to leave a comment below. Thank you for reading!

0 0 votes
Article Rating
24 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@AkashYadav-tc2lo
1 month ago

response.end() where do get this ?

@DZM47
1 month ago

Those who can't able to find "App Password" option after the search, they need to first turn on 2-step Verfication than they will be able to see that option.

@Walkerbuddy
1 month ago

brother apki video help ful toh hai lakin apka mail receive time and jab send kara ho vo toh different hai ??? asa kyu ??

@aldenEeaden
1 month ago

Sir, Is there any limitations of this method? Can I use it free & unlimited times forever?

@shwetanshusinha2690
1 month ago

Bahut hi zyada achha se explain kiye hain bhaiya … Thank u so much

@Amanbankey8
1 month ago

You always keep post this type of content for us

@vaishyasamajshaadi
1 month ago

app password not coming on search

@Amanbankey8
1 month ago

Thanks bro for creating this amazing content for us

@indimerz
1 month ago

this only works with localhost.
in production it doesnt works,
is there any way to send emails from gmail in production too?

@vipullotake3330
1 month ago

but I'm receiving mail in spam, what should I do about that?

@gauravparasar4571
1 month ago

port dena jruri h kya mera bina port k bhi chalra hai lekin yr production me mail send nahi hora

@unknownuser9124
1 month ago

Damn…..this is awesome!!!

@sudhanshushekhar4222
1 month ago

Thanks man It worked

@amargaming5126
1 month ago

Thanks bro it was helpful alot, it saved my time

@pranshubasak8796
1 month ago

Okay , i get the problem , If u want app password , first u need to activate 2 factor authentication , not just check but activate and then ur id will be elegible for app generation

@pranshubasak8796
1 month ago

Bro mere pass 8 gmail id hai , kisis me bhi app password nahi a rah hai , bussiness or personal dono , what should i do aur ye 2 factor authenctication dekh ke karna kya hai uska ??,

@tharun-jq5us
1 month ago

how to get code??

@dwchau.254
1 month ago

i dont see app password when I type in search, can u help me

@Ganesh_Golhar
1 month ago

thanks for such helpful video

@azmyasir4967
1 month ago

thanks for this video