Created
October 9, 2023 09:16
-
-
Save Ebrahim-Ramadan/61fbda873283649aeabc15334444f786 to your computer and use it in GitHub Desktop.
send 20 emails in one command - nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nodemailer = require('nodemailer'); | |
const fs = require('fs'); | |
// Create a transporter using Gmail SMTP | |
const transporter = nodemailer.createTransport({ | |
service: 'Gmail', | |
auth: { | |
user: '[email protected]', // Your Gmail address | |
pass: 'your Application-specific password here', // Your Application-specific password | |
}, | |
}); | |
const recipients = [ | |
{ name:'kalmnyishara', email: '[email protected]' }, | |
// Add the rest of the companies and their email addresses | |
]; | |
const resumeFile = fs.readFileSync('./my resume.pdf'); | |
const subject ='Frontend application' | |
const emailContent = ` | |
<div> | |
<div> | |
Dear [Company Name] | |
</div> | |
<div> | |
My name is Ebrahim Ramadan and I am a sophomore computer science student | |
at E-JUST. As a web developer, I am seeking a junior-level position in a | |
space that allows me to expand my skills and learn about software | |
development. | |
</div> | |
<div> | |
The work intalio is doing is exactly the work I want to be part of. That | |
is why I am applying for the position of Front-end developer. I look | |
forward to hearing from you soon. | |
</div> | |
<div>Thank you,</div> | |
<div>Ebrahim Ramadan</div> | |
</div> | |
`; | |
recipients.forEach((company) => { | |
const mailOptions = { | |
from: '[email protected]', | |
to: company.email, | |
subject: subject, | |
html: emailContent.replace('[Company Name]', company.name), | |
attachments: [{ filename: 'resume.pdf', content: resumeFile }], | |
}; | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) { | |
console.error(`Error sending email to ${company.name}: ${error}`); | |
} else { | |
console.log(`Email sent to ${company.name}: ${info.response}`); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "mailsending", | |
"lockfileVersion": 3, | |
"requires": true, | |
"packages": { | |
"": { | |
"dependencies": { | |
"nodemailer": "^6.9.5" | |
} | |
}, | |
"node_modules/nodemailer": { | |
"version": "6.9.5", | |
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.5.tgz", | |
"integrity": "sha512-/dmdWo62XjumuLc5+AYQZeiRj+PRR8y8qKtFCOyuOl1k/hckZd8durUUHs/ucKx6/8kN+wFxqKJlQ/LK/qR5FA==", | |
"engines": { | |
"node": ">=6.0.0" | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"nodemailer": "^6.9.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment