If you have any query feel free to chat us!
Happy Coding! Happy Learning!
To send an email using Nodemailer and SMTP, we first need to install nodemailer via npm. After installing nodemailer, we can create a transport object with the SMTP credentials, set up the message options, and finally use the transport object to send the email.
Here's an example of sending a test email using Nodemailer:
javascriptCopy code
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: '[email protected]',
pass: 'yourpassword'
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"Fred Foo" <[email protected]>', // sender address
to: '[email protected], [email protected]', // 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 sent: %s', info.messageId);
// Preview only available when sending through an Ethereal account
console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
});
In this example, we create a transporter object using the SMTP credentials for a Gmail account. We set up the email options with a sender address, list of receivers, subject line, and both plain text and HTML versions of the email body. Finally, we use the transporter object to send the email, and log the message ID and preview URL if the email was sent successfully.
Comments: 2
I am not able to access videos from second class and further. I have already completed first class
When will I get my course?
Now, Your query was resolved.