Skip to content

Instantly share code, notes, and snippets.

@timmypidashev
Last active August 30, 2021 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmypidashev/db2bf593233cd0f2fc2a13ca3f3bc108 to your computer and use it in GitHub Desktop.
Save timmypidashev/db2bf593233cd0f2fc2a13ca3f3bc108 to your computer and use it in GitHub Desktop.
Birthday reminders sent in bulk to my email...
function main() {
// Load the sheet that contains the birthdays.
var sheet = SpreadsheetApp.getActive().getSheetByName("sheet1");
// Get the last row in the sheet that has data.
var numRows = sheet.getLastRow();
// Load data in the first two columns from the second row till the last row.
// Remember: The first row has column headers so we don’t want to load it.
var range = sheet.getRange(2, 1, numRows - 1, 2).getValues();
// Use a for loop to process each row of data
for(var index in range) {
// For each row, get the person’s name and their birthday
var row = range[index];
var name = row[0];
var birthday = row[1];
// Check if the person’s birthday is today
if(isBirthdayToday(birthday)) {
//If yes, send an email reminder
emailReminder(name);
}
}
}
// Check if a person’s birthday is today
function isBirthdayToday(birthday) {
// If birthday is a string, convert it to date
if(typeof birthday === "string")
birthday = new Date(birthday);
var today = new Date();
if((today.getDate() === birthday.getDate()) &&
(today.getMonth() === birthday.getMonth())) {
return true;
} else {
return false;
}
}
// Function to send the email reminder
function emailReminder(name) {
var subject = "Birthday reminder: " + name;
var recipient = Session.getActiveUser().getEmail();
var body = "It is " + name + "'s birthday today.";
MailApp.sendEmail(recipient, subject, body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment