Skip to content

Instantly share code, notes, and snippets.

@gesslar
Last active February 11, 2020 04:19
Show Gist options
  • Save gesslar/aa7adeeb5f75823a357a7a04fe039110 to your computer and use it in GitHub Desktop.
Save gesslar/aa7adeeb5f75823a357a7a04fe039110 to your computer and use it in GitHub Desktop.
Google Apps Script Daily Birthday Notifications
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