user2209331
user2209331

Reputation: 11

MailApp.sendEmail not firing

My function below doesn't seem to be firing off any sort of email when the function is called in onEdit(event). I have tried both EmailApp and GmailApp, any help on the matter would be greatly appreciated.

I have also tried to use my personal @gmail.com account and neither will send an email to it again.

function sendAlert() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var cell = ss.getActiveCell().getA1Notation()

  var subject = 'Update to '+sheet.getName();
  var body = sheet.getName() + ' has been updated.  Visit ' + ss.getUrl() + ' to view the changes on cell ' + cell;
  GmailApp.sendEmail('[email protected]', subject, body);
};

Upvotes: 1

Views: 1190

Answers (1)

Serge insas
Serge insas

Reputation: 46794

Is your function sendAlert() called from an onEdit() function?

The simple onEdit function is unable to send mails, as is described in the documentation. Therefore, use an installable onEdit trigger instead. This last one will ask for authorization and then execute as expected.

The triggers are in the ressource tab in the script editor, it looks like this: enter image description here

Note: If you are re-using an existing onEdit() function, remember to rename it so it will no longer act as a simple trigger function.

Upvotes: 2

Related Questions