-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
60 lines (48 loc) · 1.34 KB
/
server.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
const xlsx = require('xlsx');
const AWS = require("aws-sdk");
const fs = require("fs");
AWS.config.update({
accessKeyId: "<your access key>",
secretAccessKey: "<your access secret>",
region: "us-east-1"
});
const ses = new AWS.SES({
apiVersion: "2010-12-01"
});
function sendEmail() {
let workbook = xlsx.readFile('./inkloft.xlsx');
let data = xlsx.utils.sheet_to_json(workbook.Sheets["Sheet1"]);
let emailIds = data.map((item) => {
return item.email;
});
let htmlText = fs.readFileSync("./newsletter.txt").toString();
//console.log(htmlText);
const params = {
Destination: {
ToAddresses: emailIds // Email address/addresses that you want to send your email
},
Message: {
Body: {
Html: {
// HTML Format of the email
Charset: "UTF-8",
Data: htmlText
}
},
Subject: {
Charset: "UTF-8",
Data: "Test email"
}
},
Source: "info@inkloft.in"
};
const sendEmail = ses.sendEmail(params).promise();
sendEmail
.then(data => {
console.log("Done" + JSON.stringify(data));
})
.catch(error => {
console.log(error);
});
}
sendEmail();