0
votes

I'm trying to send a notification using MailApp.sendEmail on editing a google spreadsheet (even on addition of new row or editing existing data)

Here is the code I wrote:

function onEdit(e) {    
    var emailId = SpreadsheetApp.getActiveSheet().getRange(e.range.getLastRow(), 2, 1, 1).getValues();
    var desc = SpreadsheetApp.getActiveSheet().getRange(e.range.getLastRow(), 5, 1, 1).getValues();
    var guid = SpreadsheetApp.getActiveSheet().getRange(e.range.getLastRow(), 6, 1, 1).getValues();
    MailApp.sendEmail(emailId, guid, guid);
    // Browser.msgBox(emailId + guid);
}

This code is extracting the edited data which I can see using Browser.msgBox(emailId + guid); (but only if placed before the MailApp.sendEmail and not if placed after MailApp.sendEmail function). When I use MailApp.sendEmail function with some other function, it executes well and is sending the mails too. But not in this function.

Any help or pointers to resolve this?

1

1 Answers

0
votes

The special onEdit() trigger function is called a Simple Trigger. Check the documentation here.

(Simple Triggers) cannot access any services that require authentication as that user. For example, the Google Translate service is anonymous and can be accessed by the simple triggers. Google Calendar, Gmail, and Sites are not anonymous and the simple triggers cannot access those services.