-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.gs
65 lines (38 loc) · 1.59 KB
/
code.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
// works on Google Sheet
function SendMail(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ws = ss.getSheetByName("Mailer 3000");
const name = ws.getRange("E4").getValue();
// met la date et l'heure au format texte
var txt1 = ws.getRange("C8");
var txt2 = txt1.setNumberFormat('@');
var txt3 = ws.getRange('C10');
var txt4 = txt3.setNumberFormat('@');
var date =
ws.getRange("C8").getValue(); // date
var hour =
ws.getRange("C10").getValue(); // heure
const mailAdress = ws.getRange("I4").getValue(); //mail value
const htmlTemplate = HtmlService.createTemplateFromFile("email") //replaces the HTML values with the values from the code file
htmlTemplate.name = name;
htmlTemplate.date = date;
htmlTemplate.hour = hour;
const htmlForEmail = htmlTemplate.evaluate().getContent() //Fills the HTML with the new values
console.log(htmlForEmail);
GmailApp.sendEmail(
mailAdress, //destinatire
"Entretien d'embauche - "+ name, // sujet
"Merci d'ouvrir cet email avec une boite mail prenant en charge le HTML", //in case of error with mail client
{ htmlBody: htmlForEmail } //corps en HTML
);
//resets the format to date mode in order to use the calendar
var txt5 = txt1.setNumberFormat('dd-MM-yyyy');
// +1 coutner
var range = ws.getRange("E8");
var value = range.getValue();
range.setValue(value + 1);
//Notification toast
var message = 'Le mail a été envoyé à '+ name
var title = 'Mail envoyé ✅';
SpreadsheetApp.getActiveSpreadsheet().toast(message, title);
}