-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSendCalendarEventsForToday.js
51 lines (36 loc) · 1.63 KB
/
SendCalendarEventsForToday.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
51
function eventsForToday() {
// Calendar ID of A/V Calendar
var calendarId='FILLINTHEIDOFYOURGOOGLECALENDAR';
// Who should get the email of the results
var recipients='[email protected]';
// What is the subject of the email you want to send
var subject='These are the events for today';
// Get the calendar based on the ID
var calendar = CalendarApp.getCalendarById(calendarId);
// The begin date is today right now... no end date
var beginDate = new Date(Date.now());
// Get the calendar events for today
var calEvents = calendar.getEventsForDay(beginDate);
// Set up an empty email body we'll fill in later with information
var body='';
// Loop through calendar events for today
for (var j = 0; j < calEvents.length; j++) {
// Set local variable for this particular event
var calEvent = calEvents[j];
// Get the other relevant info about the event
var calEventDateCreated = calEvent.getDateCreated();
var calDescription = calEvent.getDescription();
var calTitle = calEvent.getTitle();
var calStart = calEvent.getStartTime();
var calEnd = calEvent.getEndTime();
var calEventCreator = calEvent.getCreators();
// Add info to the body of the email
body+='Title: ' + calTitle + '\nDescription: ' + calDescription + '\nStart: ' + calStart + '\nEnd: ' + calEnd + '\nDate Created: ' + calEventDateCreated + '\nCreator(s): ' + calEventCreator + '\n\n';
}
// Placeholder text if there are no events
if(body==''){
body='There are no events today';
}
// Send an email of the results (or lack of results)
MailApp.sendEmail(recipients, subject, body);
}