-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkt_acquisition
More file actions
84 lines (71 loc) · 2.12 KB
/
kt_acquisition
File metadata and controls
84 lines (71 loc) · 2.12 KB
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
const DATA_SHEET = SpreadsheetApp.openById("1HwHSxhBBscyiI8gzA1oCNGScNq8Yyd5Gulngw1v5Xac").getSheetByName("DATA");
//Num_Rows anpassen - aktuell von Row 2 bis Row 21 also 20 Mails
const NUM_ROWS = 21;
const START_ROW = 2;
const START_COL = 1;
const BODY_PLAIN = "plainMail.html";
const ATTACHMENT = DriveApp.getFileById("1aQv62m6TzuUq722uxijrJzaj7QJ-sThe").getBlob();
const FIELDS = {
company: 0,
email: 1,
teamPersonal: 2,
formal: 3,
firstName: 4,
lastName: 5,
teamName: 6
}
function sendAcquisitionMails() {
const data = DATA_SHEET.getRange(START_ROW, START_COL, NUM_ROWS + 1).getValues();
let userName = getUsername();
if(userName == "") {
userName = "KT-Team";
}
for(let inx = 0; inx < data.length; inx++) {
const account = data[inx];
if(account[FIELDS.email] === "" ){
continue;
}
let mailVars = {
formal: account[FIELDS.formal],
company: account[FIELDS.company],
userName: userName,
contact: ""
}
if(account[FIELDS.teamPersonal] === "Team") {
mailVars.contact = account[FIELDS.teamName];
} else {
mailVars.contact = account[FIELDS.lastName];
}
const htmlBody = buildHtmlBody(BODY_PLAIN, mailVars);
Logger.log(inx + ": " + account[FIELDS.email])
let mailObject = {
htmlBody: htmlBody,
name: "Jean Weber",
noReply: false,
replyTo: "jean.weber@fuks.org",
subject: "Ihre Anzeige im Studierendenmagazin Karlsruher Transfer",
// TODO: Uncomment
//to: account[FIELDS.email],
to: "jean.weber@fuks.org",
attachments: ATTACHMENT,
};
// console.log(mailObject);
// console.log("Send mail to ", mailObject.to);
MailApp.sendEmail(mailObject);
// TODO: Comment
// break;
}
}
function buildHtmlBody(fileName, varObject) {
let htmlTemplate = HtmlService.createTemplateFromFile(fileName);
htmlTemplate.mailVar = varObject;
return htmlTemplate.evaluate().getContent();
}
function getUsername() {
var email = Session.getEffectiveUser().getEmail();
var self = ContactsApp.getContact(email);
if (self) {
return self.getFullName();
}
return "";
}