Sending Our First Email via SMTP

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 375:- Sending Our First Email via SMTP

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.

44. Parallel Jobs + Mailer

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support