On this page
Tracks

Mail sending Nodejs Script

Last reviewed 2 Sept 2026

const fs = require('fs');
const xlsx = require('xlsx');
const nodemailer = require('nodemailer');
const { exit } = require('process');

// download the above packages

// Load your Excel file

const workbook = xlsx.readFile(’./list.xlsx’); // Path for the sheet in your local folder

const sheetName = ‘Bytedance’; // Change to the name of your sheet

const worksheet = workbook.Sheets[sheetName];
const data = xlsx.utils.sheet_to_json(worksheet);

// Email configuration

const newTransporter = ()=>{
return nodemailer.createTransport({
pool: true,
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: "you@example.com",
pass: process.env.SMTP_PASSWORD

},

});
}
const transporter = newTransporter();
const sendEmail = async (row) => {
const { Name, Company, Email, Role, Link } = row; // Adjust column names accordingly
const nameParts = Name.split(' ');
const name = nameParts[0];
const mailOptions = {
from: 'Your App <you@example.com>',
to: Email,
subject: `Request for an Interview Opportunity - ${Role} at ${Company}`,
html: `

Greetings ${name},

I'm Your Name, a Software Developer at Your Company. I got to know through your linkedin post that ${Company} is looking for a ${Role}, therefore, I have mailed you to tell you about myself. I have:

  • X years of hands-on experience in your domain
  • X years as a Your Role at Your Company
  • Worked extensively in JavaScript, Typescript, React & Next.js
  • Familiar with REST, GraphQL, monorepo codebases, Jest & React Testing library
  • Worked on a product with a notable scale or result.

Currently, I am serving a notice period and can join within 15 days of receiving an offer. A little help from your side can significantly help my career.

PS: I have attached my Resume & Linkedin Profile ${Link !== undefined ? \`& ${Role} Opening\`: '' } for you to take a look at. If you find me suitable, please help me with an Interview Opportunity at ${Company}.

Thanking You

Regards,

Your App

Contact No: +91 9876543210

\`
};
try {
await transporter.sendMail(mailOptions);
console.log('Email sent to', Email);

} catch (error) {

console.error('Error sending email:', Email, error);
}
};
const sendEmailsSynchronously = async () => {
for (const row of data) {
await sendEmail(row);

await new Promise((resolve) => setTimeout(resolve, Math.random()*90000)); // Pause for 1 minute (adjust the duration as needed)

}
console.log("Done Sending mails")

exit()

};

// Call the function to send emails

sendEmailsSynchronously();