Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WEB ENGINEERING

Lab Report No. 14

Section “A”

Submitted by:
Tayyab Rasheed (19-cs-014)

Submitted to:
Sir Adnan Javed
Tasks:

Lab Task: Sending Email with Nodemailer


Requirements
1. You need to create a Node.js script that sends an email to a recipient using Nodemailer. The
email
should contain the following details:
From: your email address (use any email service of your choice)
To: recipient email address
Subject: "Test Email from Node.js"
Body: “Hello from Node.js!”

Code:

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({


service: 'your-email-service',
auth: {
user: 'your-email@example.com',
pass: 'your-password',
},
});

const mailOptions = {
from: 'your-email@example.com',
to: 'recipient@example.com',
subject: 'Test Email from Node.js',
text: 'Hello from Node.js!',
};

transporter.sendMail(mailOptions, (error, info) => {


if (error) {
console.error(error);
} else {
console.log('Email sent:', info.response);
}
});
node sendEmail.js

Output:

Email sent: <response from the email service>

You might also like