-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSender.gs.txt
97 lines (84 loc) · 4.1 KB
/
Sender.gs.txt
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
90
91
92
93
94
95
96
97
function sendBirthdayGreetings() {
// Open the current sheet
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
// Get today's date
var today = new Date();
var todayMonth = today.getMonth() + 1;
var todayDay = today.getDate();
// Iterate through the contacts in the sheet
var lastRow = sheet.getLastRow();
for (var i = 2; i <= lastRow; i++) {
var nameCell = sheet.getRange(i, 1); // Assuming name is in column A
var birthdateCell = sheet.getRange(i, 5); // Assuming birthdate is in column E
if (birthdateCell.getValue() !== "") {
var birthdate = new Date(birthdateCell.getValue());
// Check if birth year is null, use the current year
var birthdateYear = birthdate.getFullYear();
if (isNaN(birthdateYear)) {
birthdate.setFullYear(today.getFullYear());
}
var birthdateMonth = birthdate.getMonth() + 1;
var birthdateDay = birthdate.getDate();
// Check if it's the contact's birthday
if (todayMonth === birthdateMonth && todayDay === birthdateDay) {
// Loop through email columns (B, C, D in this example)
for (var j = 2; j <= 4; j++) {
var email = sheet.getRange(i, j).getValue(); // Assuming email is in column B, C, D
// Send birthday greeting email for each email address
if (email != "") {
var subject = "Happy Birthday!";
var recipientName = nameCell.getValue();
//var body=`
// <div style="text-align: center; font-family: Georgia, serif;">
// <h1 style="font-size: 40px"><i>Dear ${recipientName},</i></h1>
// <h1 style="color: #FF1493; font-size: 30px"><i>Happy Birthday!</i></h1>
// <p style="font-size: 18px">${message()}</p></div>`
var body=`
<div style="text-align: center; font-family: Georgia, serif;">
<h1 style="font-size: 40px"><i>Dear ${recipientName},</i></h1>
<h1 style="color: #FF1493; font-size: 30px"><i>Happy Birthday!</i></h1>
<p style="font-size: 18px">May your day be a kaleidoscope of joy, sprinkled with laughter, wrapped in love, and topped with endless adventures. Here's to making this year as vibrant and extraordinary as you are! 🎉🎂</p>
</div>
<div style="text-align: left; font-family: Georgia, serif; margin-top: 20px; border-top: 1px solid #ddd; padding-top: 10px;">
<p style="margin: 0; font-size: 16px; font-weight: bold;"><a href="https://touhidul.com/">Touhidul Islam</a></p>
<p style="margin: 0; font-size: 14px;">B.Sc in Electrical and Electronic Engineering</p>
<p style="margin: 0; font-size: 14px;">Islamic University of Technology (IUT), Gazipur-1704, Bangladesh</p>
</div>
`;
// Send email
MailApp.sendEmail({
to: email,
subject: subject,
htmlBody: body
});
}
}
}
}
}
}
function message()
{
var apiKey = 'PLACE YOUR API TOKEN HERE';
var url = 'https://api.openai.com/v1/chat/completions';
var options = {
'method' : 'post',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + apiKey
},
'payload' : JSON.stringify({
'messages': [
{"role": "system", "content": "Give me a short birthday wish"},
// {"role": "user", "content": "Who won the world series in 2020?"},
// {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
// {"role": "user", "content": "Where was it played?"}
],
'model': "gpt-3.5-turbo"
})
};
var response = UrlFetchApp.fetch(url, options);
var json = JSON.parse(response.getContentText());
return json.choices[0].message.content
//Logger.log(json.choices[0].message.content);
}