MailApp.sendEmail error message - "there is no permission to call sendEmail"

When I change something in my table, the onEdit() trigger is onEdit() , and I can see all the msgbox that I entered in my code.

My function stops at this line

 MailApp.sendEmail(emailAddress, subject, message); 

I never see the message "Sent by email!" and I get the error message "TRANSCRIPT RECORD":

You do not have permission to call sendEmail

If I run the script directly in the script editor, everything works fine ...

Here is my code:

 function onEdit() { var sheet = SpreadsheetApp.getActiveSheet(); var sheetname = sheet.getName() var AcCellRange = sheet.getActiveCell() var AcCol = AcCellRange.getColumn() var AcRow = AcCellRange.getRow() if (sheetname=="Questions/Réponses") { //Browser.msgBox(AcCol+' / '+AcRow) //liste d'instructions //Boucle si les colonne sont comprise dans le range if ((AcCol==3) || ((AcCol==7))){ //Browser.msgBox(AcCol) if (AcRow > 7){ //Browser.msgBox(AcRow) sendEmails() } } } else {} } function sendEmails() { Browser.msgBox('SendEmails') var spreadsheet = SpreadsheetApp.getActive(); var sheet = spreadsheet.getSheetByName('ListCourriel'); Browser.msgBox('SendEmails2') var sheetDonnee = spreadsheet.getSheetByName('Questions/Réponses'); var RangeProjet = sheetDonnee.getRange(1, 3) var NoProjet = RangeProjet.getValue() var RangeProjet = sheetDonnee.getRange(4, 3) var ProjName = RangeProjet.getValue() Browser.msgBox('SendEmails3') var startRow = 2; // First row of data to process var LastRows = sheet.getRange(1,4) var numRows = LastRows.getValue(); // Number of rows to process // Fetch the range of cells A2:B3 var dataRange = sheet.getRange(startRow, 1, numRows, 2) // Fetch values for each row in the Range. var data = dataRange.getValues(); Browser.msgBox('SendEmails4') //Permet d'aller cherche les info de la ligne active var ActiveCellRange = sheetDonnee.getActiveCell() var ActiveRows = ActiveCellRange.getRow() var NoLigne = sheetDonnee.getRange(ActiveRows,1) var sDep = sheetDonnee.getRange(ActiveRows,2) var sDate = sheetDonnee.getRange(ActiveRows,4) var sInitiale = sheetDonnee.getRange(ActiveRows,5) var sQuestion = sheetDonnee.getRange(ActiveRows,3) Browser.msgBox('SendEmails5') var rDate = sheetDonnee.getRange(ActiveRows,9) var rInitiale = sheetDonnee.getRange(ActiveRows,10) var rReponse = sheetDonnee.getRange(ActiveRows,7) Browser.msgBox('SendEmails6') var subject = 'Modif. Question/Réponse - Projet: ('+NoProjet+') '+ProjName; var message = "No Ligne : "+NoLigne.getValue()+String.fromCharCode(10)+String.fromCharCode(10)+"Reponsable : "+sInitiale.getValue()+String.fromCharCode(10)+"Date : "+sDate.getValue()+String.fromCharCode(10)+"Question : "+String.fromCharCode(10)+sQuestion.getValue()+String.fromCharCode(10)+String.fromCharCode(10)+"************************************"+String.fromCharCode(10)+String.fromCharCode(10)+"Reponsable : "+rInitiale.getValue()+String.fromCharCode(10)+"Date : "+rDate.getValue()+String.fromCharCode(10)+"Réponse : "+String.fromCharCode(10)+rReponse.getValue() //Browser.msgbox(subject) Browser.msgBox('SendEmails7') for (i in data) { Browser.msgBox('SendEmails8') var row = data[i]; var emailAddress = row[0]; // First column Browser.msgBox('SendEmails9') MailApp.sendEmail(emailAddress, subject, message); Browser.msgBox('Email sent') } } 
+5
source share
1 answer

The permissions are different when the SIMPLE onEdit() trigger is onEdit() . In contrast, there is an INSTALLABLE trigger. Here is the documentation for simple trigger constraints:

Google Documentation - Triggers - Limitations

The documentation states:

They (SIMPLE trigger) cannot access services requiring authorization. For example, a simple trigger cannot send an email because Gmail requires authorization

You need to configure the installation trigger to send email.

From the EDIT menu, select CURRENT PROCEDURES .

Call your function something other than onEdit .

+6
source

Source: https://habr.com/ru/post/1215322/


All Articles