google apps script - Cannot execute sendEmail from trigger function -


I want to see that this is possible, I have developed a Google Form, where there is a date picker spreadsheet output, I see if the user is under 18 or not. If the user is under 18, then I want to trigger an email.

I got a share of email, but only when I execute the code from within the Google Script window. (I still need the trigger to work, it gives me you do not have permission to call sendmail ) but I can not run any problem from within the Google Script environment

I know how I will calculate the date, IE getTheYear () - getCurrentYear () , and wrap it within an IF second block, which includes the email execution script.

Here's my attempt I do not think I'm away

  function ageChecker () {var sheet = SpreadsheetApp.getActiveSheet ( ); Var valtest = sheet.getRange ("I2"). GetValue (); Var cell = sheet.getActiveCell (); Var msg = "warning student is less than 18 x" var ui = SpreadsheetApp.getUi (); // Get real cell value // var response = ui.alert (valteST, ui.ButtonSet.YES_NO); // valTest output TUE SEPT 17 1991 00:00:00 GMT + 0100 (BST) var D = new date (); Var Timestamp = DGetTime (); // Number of MS since January 1, 1970 / var response = ui.alert (d, ui.ButtonSet.YES_NO); Var Age = Waltest-D; Var response = ui.alert (age, ui.ButtonSet.YES_NO); If (Waltest == 18) {MailApp.sendEmail ("email@domain.ie", "Student error", msg); }}  

There is a similar problem here. Mogsadad said:

Since the custom works (scripts called Spreadsheets Functions) are open to any user of the spreadsheet, Therefore they are not allowed to use any service for which authentication is required. This is the reason why you can not send mail to one.

This is different from the process of authorizing a script to access your services. This error message makes misleading, but the rest assured that the way you were implementing the script was in the same way.

There is no problem because the custom function is a bad way to take any kind of action, because the function will be re-evaluated every time, there will be a change in the spreadsheet, the more you want Send emails.

I suggest that you create a menu item for this operation. (If you create a new spreadsheet script, look at the sample code given in the editor.) The workflow will have to move the cursor to the row on which you want to process, then use the menu to "create it" , Which will implement your script.


Comments

Popular posts from this blog

c# - NewtonSoft JArray - how to select multiple elements with LINQ -

c# - Process.Kill() returns access denied -

c# - Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments -