To send the email in Nodejs through nodemailer package.
Firstly installed nodemailer package.
npm install --save nodemailer
Now open the URL https://mailtrap.io/
create the signup

get the username and password

Now, create the email.js file and write the below code
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: 'smtp.mailtrap.io',
port: 2525,
auth: {
user: 'put_your_username_here', //put_your_username_here
pass: 'put_your_password_here' //put_your_password_here
}
});
var mailOptions = {
from: 'fromemail@abc.com',
to: 'toemail@abc.com',
subject: 'Test Email',
html: 'HTML body text data
'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Output:-
Email sent: 250 2.0.0 Ok: queued
Check the send email content in mailtrap inbox

C# Dictionary – Interview Questions
Q 1: How do you send email in Node.js?
Ans: Using libraries like Nodemailer.
Q 2: What is Nodemailer?
Ans: A module for sending emails from Node.js applications.
Q 3: Which protocol is used?
Ans: SMTP.
Q 4: Can Node.js send attachments?
Ans: Yes, using Nodemailer.
Q 5: Is email sending async?
Ans: Yes, it is asynchronous.