How to Custom Email Notifications with Google Apps Script

Dilip Kashyap
3 min readFeb 16, 2024

--

Image Source: Pixabay

In the ever-evolving landscape of modern workplaces, effective communication remains the cornerstone of successful collaboration. Google Workspace offers a suite of powerful tools to streamline workflows, but sometimes standard notifications fall short of meeting specific communication needs. This is where custom email notifications, powered by Google Apps Script, come into play.

Understanding Custom Email Notifications

Custom email notifications allow users to receive tailored alerts for specific events or triggers within their Google Workspace environment. Whether it’s notifying team members about new form submissions, reminding stakeholders of upcoming deadlines, or alerting managers to critical changes in shared documents, custom email notifications ensure that important information reaches the right people at the right time.

Developing Custom Email Notifications with Google Apps Script

Google Apps Script, a cloud-based scripting language developed by Google, provides a powerful platform for extending the functionality of Google Workspace applications. Below is a step-by-step guide to developing custom email notifications using Google Apps Script:

1. Define Trigger Events: Identify the events or triggers for which you want to send custom email notifications. For this example, let’s consider sending an email notification when a specific keyword is detected in a Google Sheets document.

2. Write the Script:

// Define a function to send custom email notifications
function sendCustomEmailNotification() {
// Access the active spreadsheet
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();

// Access the active sheet
var sheet = spreadsheet.getActiveSheet();

// Define the keyword to trigger the email notification
var keyword = "urgent";

// Get the range of cells to search for the keyword
var range = sheet.getDataRange();

// Get the values in the range
var values = range.getValues();

// Iterate through the values to check for the keyword
for (var i = 0; i < values.length; i++) {
for (var j = 0; j < values[i].length; j++) {
if (values[i][j] === keyword) {
// If the keyword is found, send an email notification
var recipient = "recipient@example.com";
var subject = "Custom Email Notification";

//======== You may add any specific paramters from sheet to here =========

var body = "The keyword '" + keyword + "' was found in the spreadsheet.";
MailApp.sendEmail(recipient, subject, body);

// Exit the loop if the keyword is found
return;
}
}
}
}

3. Set up Triggers: To execute the sendCustomEmailNotification function automatically, set up a trigger in Google Apps Script to run the function based on specific criteria (e.g., when the spreadsheet is edited).

4. Test and Deploy: Test the script to ensure it functions as expected. You can manually trigger the script by running the sendCustomEmailNotification function from the Apps Script editor. Once tested, deploy the script to your Google Workspace environment.

Conclusion

Custom email notifications, powered by Google Apps Script, offer a flexible solution for enhancing communication within Google Workspace. By leveraging the capabilities of Apps Script, developers can create personalized alerts tailored to their organization’s unique needs. Whether it’s monitoring spreadsheet changes, tracking form submissions, or responding to specific triggers, custom email notifications ensure that critical information is communicated effectively, fostering collaboration and productivity in the modern workplace.

I hope you find this article helpful. For latest post intimation you may follow, subscribe and share this with your friends. Happy learning! 💻🥳🎉

Boost your Google Workspace potential with our e-book: Google Apps Script: A Beginner’s Guide. Streamline your workflow and automate tasks today. Get your copy now!

Open to freelance opportunities and welcome to collaborations. Please feel free to contact me via email at dilipkashyap.sd@gmail.com. Thank you :)

--

--

Dilip Kashyap

Software Developer at IIT Gandhinagar | Google Workspace | Contact me at dilipkashyap.sd@gmail.com