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

Leave a Reply

49 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ThapaTechnical
2 hours 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
2 hours ago

thanks a lot!

@priyadarshi5730
2 hours ago

💚💚💚

@itsmkb1213
2 hours ago

Upload the other version for real world projects also

@amanprajapati9252
2 hours ago

Hello sir, how your vscode is firing 😂

@saurabhkumar6045
2 hours ago

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

@RoyBombale
2 hours ago

time passs

@BajarangDal-2
2 hours ago

Ye free hai kuchh pice laga tha hai

@AmanKumar-r5r2b
2 hours ago

i dont have any app.js file

@good114
2 hours ago

🙏🙏❤❤

@Its_shubhampant
2 hours ago

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

@hibyeandgood
2 hours ago

🙏🙏

@hardikdangodara3272
2 hours ago

nahi ho raha hai bhai

@Anubhav-hd1qi
2 hours ago

can i use official mail
(website mail?)

@sagardutta753
2 hours 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
2 hours ago

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

@VedantRajankar
2 hours 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
2 hours ago

sir ji you are making very good content

@bharathkesari7350
2 hours ago

thanks broooooooooooooooooo

@stith_pragya
2 hours ago

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

49
0
Would love your thoughts, please comment.x
()
x