forked from colejoh/quarantine-buster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (47 loc) · 1.35 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
const csvToJson = require("csvtojson/v2");
const fs = require('fs');
const nodemailer = require('nodemailer');
const config = require('./config.json');
const transporter = nodemailer.createTransport(config);
const sendMail = (options) => {
return new Promise((resolve, reject) => {
console.log(`Sending ${options.to}`);
transporter.sendMail(options, (error, info) => {
if (error) {
reject(error);
} else {
resolve(`Message sent to ${options.to}`)
}
});
})
}
(function () {
const csv_path = process.argv[2];
const template_path = process.argv[3];
const failed = [];
if (!csv_path || !template_path) {
console.error("usage: node index.js ./list.csv ./template.html\n");
return;
}
csvToJson().fromFile(csv_path).then(async (people) => {
const template = fs.readFileSync(template_path, 'utf8');
for (const person of people) {
const content = template.replace('hacker', person.first_name);
const options = {
from: config.auth.user,
to: person.email,
subject: 'BoilerMake Exec Team Recruitment',
html: content
};
try {
await sendMail(options);
} catch (err) {
failed.push(options.to)
console.log(err);
}
}
if(failed.length) {
console.log('failed: ' + failed);
}
})
}());