Node.js में Ethereal का उपयोग करके Nodemailer के साथ ईमेल भेजें

Posted by


Nodemailer is a popular Node.js module that allows you to easily send emails from your Node.js applications. In this tutorial, we will learn how to send emails using Nodemailer with Ethereal, which is a fake SMTP service that lets you test your emails without actually sending them.

Step 1: Install Nodemailer

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

npm install nodemailer

Step 2: Create a Nodemailer transporter

Next, you need to create a Nodemailer transporter that will be used to send emails. You can do this by requiring the Nodemailer module and creating a transporter object with the following code:

const nodemailer = require('nodemailer');

let transporter = nodemailer.createTransport({
  host: 'smtp.ethereal.email',
  port: 587,
  secure: false,
  auth: {
    user: 'your_ethereal_username',
    pass: 'your_ethereal_password'
  }
});

In the code above, replace your_ethereal_username and your_ethereal_password with your Ethereal username and password, which you can get by signing up for an Ethereal account at https://ethereal.email/.

Step 3: Create and send an email

Now that you have created a Nodemailer transporter, you can use it to send emails. To do this, you need to create an email object with the following code:

let mailOptions = {
  from: 'your_email@example.com',
  to: 'recipient@example.com',
  subject: 'Test Email',
  text: 'This is a test email sent using Nodemailer with Ethereal!'
};

In the code above, replace your_email@example.com with your email address and recipient@example.com with the recipient’s email address.

Next, you can use the transporter.sendMail() method to send the email:

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

Step 4: Test your email

After sending the email, you can check your Ethereal inbox to see if the email was received. To do this, you can log in to your Ethereal account and view the emails in your inbox.

That’s it! You have successfully sent an email using Nodemailer with Ethereal in Node.js. This setup allows you to test your emails without actually sending them to real recipients.

0 0 votes
Article Rating
49 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ThapaTechnical
1 month ago

😀 Source Code Link: https://www.thapatechnical.com/2023/01/send-emails-with-nodemailer-using.html

😊 Become a Member, get access to perks, free Source code, & more..

https://www.youtube.com/channel/UCwfaAHy4zQUb2APNOGXUCCA/join

😍 Check my Instagram to Connect with me: https://www.instagram.com/thapatechnical

👩‍💻 Discord Server Link for Programmer to Hangout: https://discord.gg/MdScmCsua6

✌ Website Link: https://www.thapatechnical.com

@fatimaiqra2169
1 month ago

thanks a lot!

@priyadarshi5730
1 month ago

💚💚💚

@itsmkb1213
1 month ago

Upload the other version for real world projects also

@amanprajapati9252
1 month ago

Hello sir, how your vscode is firing 😂

@saurabhkumar6045
1 month ago

the fire thing that you have installed, believe me it is very annoying.

@RoyBombale
1 month ago

time passs

@BajarangDal-2
1 month ago

Ye free hai kuchh pice laga tha hai

@AmanKumar-r5r2b
1 month ago

i dont have any app.js file

@good114
1 month ago

🙏🙏❤❤

@Its_shubhampant
1 month ago

bacho wala kam sikhara ha bhai bulk mail send krne ka krke dikhao jraaa

@hibyeandgood
1 month ago

🙏🙏

@hardikdangodara3272
1 month ago

nahi ho raha hai bhai

@Anubhav-hd1qi
1 month ago

can i use official mail
(website mail?)

@sagardutta753
1 month ago

i have copied the exact code but i am getting the following error:
node:internal/process/promises:279

triggerUncaughtException(err, true /* fromPromise */);

^

Error: read ECONNRESET

at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {

errno: -4077,

code: 'ESOCKET',

syscall: 'read',

command: 'CONN'

}

[nodemon] app crashed – waiting for file changes before starting…

@MayankPrasher-ms6ki
1 month ago

u don't know how ur video helped me , I wish for ur best

@VedantRajankar
1 month ago

Hello, sir. I have a query. I want to connect my application to the server database. Currently, I am using MongoDB drivers for the database connectivity. How can I connect to the server-side database? If anyone knows, please reply.

@Sameer-codes
1 month ago

sir ji you are making very good content

@bharathkesari7350
1 month ago

thanks broooooooooooooooooo

@stith_pragya
1 month ago

Thank You So Much for this wonderful video…………🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻