العربية

Get an Email When a Google Sheets Cell Changes (Code)

Last updated: December 3, 2026

Google Sheets cell edit triggering an Apps Script function that sends an email alert

A cell edit, an installable trigger and an email alert.

Quick Answer

⚡ Quick Answer: Name the function anything except onEdit, such as onEditNotify. Install it as an installable edit trigger, using a setup function or the Triggers page, and call MailApp.sendEmail inside it. A plain onEdit is a simple trigger, and Google says simple triggers cannot send email because they run without authorization.

You can have Google Sheets email you whenever a certain cell changes, for example when someone moves an order to "Shipped". It takes about 30 lines of Apps Script and one trigger. The part that trips people up is that the obvious function name, onEdit, cannot send email. This guide gives you the code, the setup steps, and the limits to know, using Google's Apps Script documentation.

New to Apps Script? Our Google Apps Script tutorial covers the basics first.

Why a Plain onEdit Cannot Send Email

A function named onEdit runs as a simple trigger. Google's documentation says simple triggers fire without asking for authorization, so they cannot use services that need it. Its own example is that a simple trigger cannot send an email, because the Gmail service requires authorization. Simple triggers also stop after 30 seconds.

An installable trigger fixes that. Google says installable triggers can call services that require authorization, and that they always run under the account of the person who created them. So the email is sent from the account that installed the trigger.

Table comparing a simple onEdit trigger with an installable edit trigger in Google Apps Script by email sending, authorization, who it runs as and setup

Simple trigger compared with installable trigger.

Set It Up in Five Steps

Five short steps take you from an empty script to a working alert. Only step 3 needs your own values.

1. Open the script editor

In your spreadsheet, choose Extensions, then Apps Script. Delete the sample code in the editor.

2. Paste the code

Code.gs
// Settings: change these three lines
const SHEET_NAME = 'Orders';        // the tab to watch
const WATCH_COLUMN = 4;             // column D
const ALERT_EMAIL = 'you@example.com';

function onEditNotify(e) {
  const range = e.range;
  const sheet = range.getSheet();

  // Only one cell, only the watched tab and column, never the header row
  if (sheet.getName() !== SHEET_NAME) return;
  if (range.getNumRows() !== 1 || range.getNumColumns() !== 1) return;
  if (range.getColumn() !== WATCH_COLUMN || range.getRow() === 1) return;

  const oldValue = e.oldValue === undefined ? '(empty)' : e.oldValue;
  const newValue = range.getValue() === '' ? '(empty)' : range.getValue();
  if (String(oldValue) === String(newValue)) return;

  const rowLabel = sheet.getRange(range.getRow(), 1).getValue();
  const subject = `Sheet changed: ${SHEET_NAME}!${range.getA1Notation()}`;
  const body = [
    `Row: ${rowLabel}`,
    `Cell: ${range.getA1Notation()}`,
    `Old value: ${oldValue}`,
    `New value: ${newValue}`,
    '',
    e.source.getUrl(),
  ].join('\n');

  MailApp.sendEmail(ALERT_EMAIL, subject, body);
}

// Run this once from the editor to install the trigger
function createEditTrigger() {
  const exists = ScriptApp.getProjectTriggers()
    .some((t) => t.getHandlerFunction() === 'onEditNotify');
  if (exists) return;
  ScriptApp.newTrigger('onEditNotify')
    .forSpreadsheet(SpreadsheetApp.getActive())
    .onEdit()
    .create();
}

3. Change the three settings

Set SHEET_NAME to the tab you want to watch, WATCH_COLUMN to the column number (A is 1, D is 4), and ALERT_EMAIL to the address that should get the alerts. Click Save.

4. Install the trigger once

Select createEditTrigger in the function menu and click Run. Apps Script works out which permissions the code needs by scanning it, and shows an authorization dialog the first time. Grant access with the account you want the emails to come from. The function checks for an existing trigger first, so running it twice does not create a duplicate.

You can also do this by hand. Open Triggers at the left of the editor, click Add Trigger, choose onEditNotify, pick the event type On edit, and save.

5. Test it

Change a value in the watched column, outside the header row. An email should arrive within a few moments. If nothing comes, open Executions in the editor to see whether the trigger ran and what error it logged.

How the Code Works

When the trigger fires, Apps Script passes an event object, e. These are the fields the code uses, as Google documents them for edit events:

FieldWhat it holds
e.rangeThe cell or cells that were edited
e.oldValueThe value before the edit. Only available when the edited range is a single cell. Undefined if the cell was empty
e.sourceThe spreadsheet the script is bound to, used here for its URL

That is why the code returns early when the edit covers more than one cell, such as a paste. It also reads the new value with range.getValue(), so clearing a cell is reported as empty. The first checks keep the script quiet for other tabs, other columns and the header row, so you do not get an email for every edit in the file.

Limits to Know Before You Rely on It

  • Email quota. Google lists 100 email recipients per day for consumer accounts and 1,500 for Google Workspace accounts when you use MailApp, with an asterisk on both numbers on its quotas page. Check that page for the current figures.
  • Script changes do not fire it. Google says script executions and API requests do not cause triggers to run, so edits made by another script will not email you.
  • Runs as the creator. The emails come from the account that created the trigger, even when a colleague makes the edit.
  • Read-only users. Installable triggers do not run when a file is opened in view or comment mode.
  • Failures are quiet. If the function throws an error, no message appears on screen. Google emails the trigger owner a failure summary instead, and the Executions page shows the details.
  • Daily trigger runtime. The quotas page lists 90 minutes of total trigger runtime per day for consumer accounts. A short alert function is far below that.

If No Email Arrives: What to Check

Most failures come from the trigger, not the code. Work through these checks in order. Each one maps to a behavior Google documents.

Check that the trigger exists

Open Triggers at the left of the editor. You should see onEditNotify with the event type On edit. If it is missing, run createEditTrigger again. It checks for an existing trigger first, so it will not create a duplicate.

Read the Executions page

The Executions page shows whether the function ran and what error it logged. A run that ended early because the edit was in another tab, another column, the header row or a multi-cell paste is normal. It means the guard checks in the code did their job.

Check which account owns the trigger

Installable triggers run under the account of the person who created them. If a colleague installed the trigger, alerts are sent from their address and their quota is the one that counts. Install it yourself, with the account you want the emails to come from. For sorting the incoming alerts, see our Gmail labels and filters guide.

Check how the cell was changed

An edit made by typing or pasting in the spreadsheet fires the trigger. Google says script executions and API requests do not, so a value written by another script or by an import tool will not email you.

Adapting the Alert to Your Sheet

The three constants at the top are the only part most people change. A few small edits cover common cases without adding risk.

Watching a different column

Column numbers count from A as 1. To watch column F, set WATCH_COLUMN to 6. If your headers sit on more than one row, change the range.getRow() === 1 check to match.

Choosing a row label

The email names the row by reading the first column of the edited row. If your identifier lives elsewhere, change the column number in the getRange(range.getRow(), 1) call.

If you would rather skip code for simple jobs, our Google Sheets tips that replace extra apps covers built-in options, and the n8n automation guide covers a no-code automation tool.

❤️

Support Our Content

Your donation helps us keep going

Easy Variations

  • Several recipients. Pass a comma-separated list of addresses as the first argument. Google lists 50 recipients per message as the cap.
  • Several columns. Replace the column check with a list, for example [4, 6].includes(range.getColumn()).
  • One digest instead of many emails. Collect changes in a sheet and send a summary from a time-driven trigger, such as ScriptApp.newTrigger("sendDigest").timeBased().everyHours(6).create(). Google shows this pattern for time-driven triggers. The sendDigest function is yours to write.

How the Code Was Checked

The decision logic was run against stand-in objects that imitate the cell, sheet and event, covering a normal edit, an empty old value, a cleared cell, a header edit, another tab, another column, a multi-cell paste and an unchanged value. Every Apps Script method used was checked against Google's reference pages listed below. The code has not been run inside your spreadsheet, so do the test in step 5 before you depend on it.

Frequently Asked Questions About Google Sheets Email Alerts

❓ Why does my onEdit function not send email?

A function named onEdit runs as a simple trigger, and Google says simple triggers cannot use services that need authorization, including sending email. Rename the function, for example to onEditNotify, and install it as an installable edit trigger from the Triggers page or with a setup function.

❓ Can the script tell me the old value of the cell?

Yes, through e.oldValue. Google says it is only available when the edited range is a single cell, and it is undefined if the cell had no previous content. That is why the code returns early for multi-cell pastes and shows (empty) when there was no earlier value.

❓ How many emails can this send per day?

Google's quotas page lists 100 email recipients per day for consumer accounts and 1,500 for Google Workspace accounts when you use MailApp. Both numbers carry an asterisk on that page. Check the page for the current figures before you build anything that depends on a high volume.

❓ Will it email me when another script edits the sheet?

No. Google says script executions and API requests do not cause triggers to run. Only an edit made by a person in the spreadsheet fires the installable edit trigger, so values written by another script, an add-on or an import will not send an alert.

❓ Whose account sends the email?

The account that created the trigger. Google says installable triggers always run under the account of the person who created them, even when someone else makes the edit. Install the trigger while signed in with the address you want the alerts to come from.

❓ Does the trigger run when someone only views the file?

No. Installable triggers do not run when a file is opened in view or comment mode, because no edit happens. Only a person with edit access changing a cell can fire it, so viewers and commenters will never cause an alert to be sent.

Conclusion and Next Steps: Set Up Your First Alert

A Google Sheets email alert needs three things: a function with any name except onEdit, an installable edit trigger, and a MailApp.sendEmail call. The code in this guide checks the tab, column and header row so you only hear about the edits you care about.

Your next step is to paste the code, change the three settings, run createEditTrigger once, and test with a real edit. If nothing arrives, the Executions page will tell you why.

📬
Google Sheets and Apps Script Guides

Get Automation Tips That Actually Work

Practical Google Sheets and Apps Script guides, official documentation and checked code, delivered to your inbox from Valley4Techs.

🔒 100% free. No spam, ever. Unsubscribe with one click anytime.

Sources

Add Valley4Techs as a Preferred Source

Follow us on Google News for the latest updates

Add Now
Comments