-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gs
89 lines (67 loc) · 1.89 KB
/
main.gs
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
81
82
83
84
85
86
87
88
89
function onOpen()
{
var ui = SpreadsheetApp.getUi();
ui.createMenu('Automation')
.addItem('send PDF Form', 'sendPDFForm')
.addItem('send to all', 'sendFormToAll')
.addToUi();
console.log(MailApp.getRemainingDailyQuota())
}
function sendPDFForm()
{
var row = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();
sendEmailWithAttachment(row);
}
function sendEmailWithAttachment(row)
{
var client = getClientInfo(row);
//var filename= 'Atharva Kulkarni Non Technical Event, Collage Making.jpg';
var file = DriveApp.getFilesByName(client.filename);
if (!file.hasNext())
{
console.error("Could not open file "+client.filename);
return;
}
var template = HtmlService
.createTemplateFromFile('email-template');
template.client = client;
var message = template.evaluate().getContent();
MailApp.sendEmail({
to: client.email,
subject: "Engineer's Day participation Certificate",
htmlBody: message,
attachments: [file.next().getAs(MimeType.JPEG)]
});
}
function getClientInfo(row)
{
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var values = sheet.getRange(row,1,1,5).getValues();
var rec = values[0];
//console.log(rec)
var client =
{
filename: rec[4],
name: rec[1],
first_name:rec[2],
email: rec[3]
};
//client.name = client.name
return client;
}
function sendFormToAll()
{
var sheet = SpreadsheetApp.getActive().getSheetByName('Sheet1');
var last_row = sheet.getDataRange().getLastRow();
//console.log(last_row)
for(var row=2; row <= last_row; row++)
{
var sent = sheet.getRange(row,7).getValues();
if (sent!= "email sent"){
//console.log("okay")
sendEmailWithAttachment(row);
Utilities.sleep(10);
sheet.getRange(row,7).setValue("email sent");
}
}
}