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

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?