forked from poorvi-vaish/email-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (69 loc) · 2.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const ejs = require("ejs");
const fs = require("fs");
const { parse } = require("csv-parse");
const dotenv = require("dotenv");
dotenv.config();
const info = require("./mailInfo.json");
const sendMail = async () => {
const nodemailer = require("nodemailer");
const fileContent = fs.readFile(
__dirname + "/YC_companies.csv",
"utf8",
(err, data) => {
if (err) {
console.error(err);
return;
}
const data1 = data.split("\r\n");
let arr = [];
for (var i = 1; i < data1.length; i++) {
let entry = data1[i].split(",");
arr.push({
company: entry[0],
name: entry[1],
email: entry[2],
});
}
arr = JSON.stringify(arr);
// console.log(arr);
fs.writeFileSync("mailInfo.json", arr, (err) => {
if (err) throw err;
console.log("The file has been saved!");
});
return data;
}
);
let transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: {
user: "[email protected]",
pass: process.env.PASSWORD,
},
});
info.map(async (entry) => {
const data = await ejs.renderFile("./mail.ejs", {
name: "Poorvi Vaish",
school: "IIITM Gwalior",
contact: process.env.CONTACT,
company: entry.company,
receiver: entry.name,
jhaiho: "https://jhaiho.com/",
careervira: "https://www.careervira.com/",
resumeUrl:
"https://drive.google.com/file/d/1CWyItbyRHNGJjk3YJBpY8xN_yh4JBW3C/view?usp=share_link",
githubUrl: "https://github.com/poorvi-vaish",
linkedinUrl: "https://www.linkedin.com/in/poorvi-vaish/",
});
// send mail with defined transport object
let info = await transporter.sendMail({
from: '"Poorvi Vaish" <[email protected]>', // sender address
to: entry.email, // list of receivers
subject: "Application: Remote Software Engineer", // Subject line
html: data, // html body
});
console.log("Message sent: %s", info.messageId);
});
};
sendMail().catch(console.error);