Error fix
Fix "You do not have permission to call MailApp.sendEmail"
Exception: You do not have permission to call MailApp.sendEmail
Google documents that a simple trigger cannot send an email, because the Gmail service needs authorization. Keep the logic, rename the function, and install the trigger yourself.
Set it up
- Rename your onEdit function to something else, for example notifyOnEdit.
- Run installEditTrigger once and approve the permission prompt.
- Edit a cell. Check Executions (left sidebar) for the run.
The script
/**
* Fix: "You do not have permission to call MailApp.sendEmail".
* Simple triggers cannot send mail. Rename your handler (not onEdit), then run
* installEditTrigger once to create an installable trigger that can.
*/
function notifyOnEdit(e) {
if (!e || !e.range) return 'skip:no-event';
MailApp.sendEmail('you@example.com', 'Edited ' + e.range.getA1Notation(), 'New value: ' + e.value);
return 'sent';
}
function installEditTrigger() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var exists = ScriptApp.getProjectTriggers().some(function (t) {
return t.getHandlerFunction() === 'notifyOnEdit';
});
if (exists) return 'already-installed';
ScriptApp.newTrigger('notifyOnEdit').forSpreadsheet(ss).onEdit().create();
return 'installed';
}What you should see
| Function | Event |
|---|---|
| notifyOnEdit | From spreadsheet, On edit |
Triggers page after the fix. Sample values, not output from a real account.
Common errors and fixes
- It still fails
- The old simple onEdit function is still in the project. Remove or rename it.
- Two emails per edit
- Two triggers exist. Delete extras in the Triggers page.
Permissions. Running this script asks you to grant Google permissions for the services listed above, to your own script. TriggerShelf never receives your Google data. See the permissions table. Google will show "Google hasn't verified this app"; that is expected for a script you paste yourself.
TriggerShelf is independent and not affiliated with or endorsed by Google LLC. Google Sheets, Gmail, Google Drive and Apps Script are trademarks of Google LLC. Quota figures come from Google's Apps Script quotas page. Test on a copy first.