-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (38 loc) · 1.08 KB
/
app.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
var fs = require('fs');
var csv = require('csvtojson');
var nodeMailerModule = require('nodemailer');
var ses = require('node-ses')
, client = ses.createClient({ key: 'xxxxxxxxxxxxxxxxxxxxxx', secret: 'xxxxxxxxxxxxxxxxx/x' });
var ejs = require('ejs');
var file = 'studentList.csv'
var jsonArray = []
var template = './emailTemplate.ejs';
var csvStream = csv()
.fromFile(file)
.on('json',(jsonObj)=>{
jsonArray.push(jsonObj)
})
.on('done',(error)=>{
console.log('end')
sendEmail(jsonArray);
})
function sendEmail(jsonArray) {
console.log(jsonArray)
for(var i = 55; i <jsonArray.length ; i++) {
var data = {
name: jsonArray[i].Name,
project: jsonArray[i].Project
}
console.log("template",data)
ejs.renderFile(template, data, function(err, html){
client.sendEmail({
to: jsonArray[i].Email,
from: '[email protected]'
, subject: 'Congratulation for Successfully Completing Google Summer of Code',
message: html,
altText: 'plain text'
}, function (err, data, res) {
});
})
}
}