0

I was trying to send an email based on onEdit() trigger. But getting these exceptions. It's not asking me for any permission. Where can I add those gmail.send and gmail.compose permissions?

Aug 14, 2020, 9:29:23 PM Error Exception: The script does not have permission to perform that action. Required permissions: (https://www.googleapis.com/auth/gmail.send || https://www.googleapis.com/auth/gmail.compose || https://www.googleapis.com/auth/gmail.modify || https://mail.google.com/ || https://www.googleapis.com/auth/gmail.addons.current.action.compose) at emailSender(Code:54:13) at onEdit(Code:70:6)

If I run the following function it sends email to my desired mail address using the same script.

function testEmail(){
  GmailApp.sendEmail("shahrearbinamin1@gmail.com",
                      "Price Changed",
                     "test");
}

But the following email sending function does not work end up with the previous error.

function emailSender(website,name, price){
   GmailApp.sendEmail("shahrearbinamin1@gmail.com",
                      "Price Changed",
                      website+"'s "+name+" New Price : "+price);
}

function onEdit(e){
  var row = e.range.getRow();
  var column = e.range.getColumn();
  var currentSheetName = e.source.getActiveSheet().getName();
  
  if(currentSheetName==="Coles"){
    if(column===5)
    {
     var name = e.source.getActiveSheet().getRange(row,2);
     emailSender("Coles",name,e.value);
     
    }
  }
  else if(currentSheetName==="Woolworths"){
     if(column===6 && e.oldValue.length!==0){
        var name = e.source.getActiveSheet().getRange(row,2);
        emailSender("Woolworths",name,e.value);
     }
  }
   
}

Here I've found permission under File->Project Properties. Tried to add permission here Script Properties tab. But it's not adding along with following permission. enter image description here

Rubén
  • 34,714
  • 9
  • 70
  • 166
Shahrear Bin Amin
  • 1,075
  • 13
  • 31

1 Answers1

2

Simple triggers are not able to send emails. Use an installable trigger.

Reference

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166