Last active
February 11, 2020 04:19
-
-
Save gesslar/aa7adeeb5f75823a357a7a04fe039110 to your computer and use it in GitHub Desktop.
Google Apps Script Daily Birthday Notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run() { | |
const names = []; | |
const today = new Date(); | |
const calendars = CalendarApp.getAllCalendars(); | |
const pat = /^(.*)\'s birthday$/; | |
const subject = `Birthday Notifications for ${today.toString()}`; | |
const body = "The following birthdays occur today:"; | |
const myEmail = Session.getActiveUser().getEmail(); | |
calendars.forEach( calendar => { | |
const events = calendar.getEventsForDay(today); | |
events.forEach( event => { | |
const title = event.getTitle(); | |
const result = pat.exec(title); | |
if(result) names.push(result[1]); | |
}); | |
}); | |
if(names.length) { | |
GmailApp.sendEmail(myEmail, subject, `${body}\n${names.join("\n")}`, | |
{ htmlBody: `${body}<br />${names.join("<br />")}` } | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment