-
Notifications
You must be signed in to change notification settings - Fork 4
/
code.js
50 lines (40 loc) · 1.26 KB
/
code.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
function getData(i) {
var sheet = SpreadsheetApp.getActive().getSheetByName("sheet1");
var data = sheet.getRange(2, 1, 121, 25).getValues();
var stocks = [];
var stock = {};
stock.name = data[i][3];
stock.link = "" + data[i][18] + "";
stocks.push(stock);
return stocks;
}
function getEmailHtml(stockData) {
var htmlTemplate = HtmlService.createTemplateFromFile("template.html");
htmlTemplate.stockData = stockData;
var htmlBody = htmlTemplate.evaluate().getContent();
return htmlBody;
}
function sendEmail() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var numRows = 120;
var dataRange = sheet.getRange(startRow, 1, numRows, 25)
var data = dataRange.getValues();
var count = 0;
for (i in data) {
var row = data[i];
var emailAddress = row[10];
var stockData = getData(i);
var htmlBody = getEmailHtml(stockData);
// MailApp.sendEmail({
// to: emailAddress,
// subject: "[SGUET] Chúc mừng bạn đã nhận được tấm vé tham gia BIGGAME 2022!!!",
// htmlBody: htmlBody
// });
++count;
Logger.log(count);
Logger.log(stockData[0].name);
Logger.log(stockData[0].link);
Logger.log("Gửi email thành công đến" + JSON.stringify(emailAddress));
}
}