visit
Often small and medium-sized businesses use email to keep in contact with their customer. Email such as seasonal greetings, festival greetings are great; it is even more fabulous when you can personalize the email to each of your customers, such as a birthday greetings email which provides special offers to your customers for a particular month. This will greatly improve customer engagement.
Scenario: Your company has the DOB and Email of customers and wants to send a birthday email greeting to the customers to show your appreciation to them.
Format → Number → Date
This will tell google sheet that this field is a date field, you can choose the format you prefer such as
dd/MM/yyyy
or MM/dd/yyyy
according to your preferences. In this case, my sheet name will be “CustomerDb”. You can view my example of google sheet .Go to Tools → Script Editor to open up and the Authorized Google Apps Script, you will notice a file named
Code.gs
on the left of your screen and the code area on the right of your screen.function sendBirthdayEmails() {
// Get the sheet where the data is, in sheet 'CustomerDb'
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CustomerDb")
//Setting up today date, the date when the function activated
var now = Utilities.formatDate(new Date(), "GMT+8", "dd-MM");
// Get all value of the sheet
var data = sheet.getDataRange().getValues();
// Loop through each row of the sheet
data.forEach(function (row) {
// Check if the date (month and day) are matched to today date, send email when matched
if (Utilities.formatDate(new Date(row[2]), "GMT+8", "dd-MM") === now) {
Logger.log("Send Email")
MailApp.sendEmail({
to: row[3],
subject: "Happy Birthday " + row[1],
htmlBody: "Dear " + row[1] + "," + "<br>" + "<br>" +
"Happy Birthday to you! " + "<br>" + "<br>" +
"<img width='500' src='//images.pexels.com/photos/3905849/pexels-photo-3905849.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'>" +
"<br>" +
"Sincerely from," + "<br>" + "DS Company"
});
}
else {
Logger.log("Birthday Not Match")
}
});
}
Utilities.formatDate(new Date(row[2]), "GMT+8", "dd-MM") === now
The idea of this function is to schedule the
sendBirthdayEmails()
to run every day to check the birthday in the database. It is easily done as Google App Script offers a few types of triggers according to the user's needs.