title: Not allowed to execute sendEmail() from custom function, but OK in script editor
body: <p>I have been trying to find a way to send single row of data to a specific email address in a "live/running" spreadsheet that I am using within my domain, to keep track of truck drivers and their pick up numbers. I managed to piece together this little bit of code using the Google Apps Script Editor available in sheets:</p>
  
  <pre><code>function sendEmail()
  {
     var sheet = SpreadsheetApp.getActiveSheet();
     var activeRow = sheet.getActiveCell().getRow();
     var cellID = "H" + activeRow;    
     var dataRange = sheet.getRange(activeRow, 1, 1, 6);
     var EMAIL_SENT = "EMAIL_SENT";
     var data = dataRange.getValues();
     Logger.log(data[0][0]);
  
     var emailAddress = usercellnum@carrier.net;
     var message = data;
     var subject = "CG-PU#";
     var emailSent = sheet.getRange(cellID).getValue();
  
     if (emailSent != "EMAIL_SENT")
     {
       MailApp.sendEmail(emailAddress, subject, message);
       var cell = sheet.getRange(cellID);
       cell.setValue(EMAIL_SENT);
     }
    }
  SpreadsheetApp.flush();  
  }
  </code></pre>
  
  <p>Any way I can call the function from a cell in my spreadsheet like <code>=sendEmail()</code> and it should send the information from only the active row, and then flag that row as <code>EMAIL_SENT</code> so I don't accidentally do it again.</p>
  
  <p>The script runs perfect if I run it from inside script editor, and hard code the email address, but if I try and run it from the spread sheet itself I am getting the message:</p>
  
  <blockquote>
    <p>error: You do not have permission to call sendEmail (line 19, file "CPS_sendEmail.gs").</p>
  </blockquote>
  
  <p>Any assistance with this is greatly appreciated! It would help to keep my user from running back to MS Excel and Outlook.
  When I get this part of it working, I would really like it if I could have the function display a list of addresses the user can select from, or some other way of keeping the user from having to remember and type in the drivers address and carrier, but I would love to just have this much of it working as expected.</p>
  
  <p>The script would/should only be allowed to run in my Google Domain with my users, and the first time I executed it - I was sure I went through the authorization process, but don't truly understand that part of things.</p>
  
  <p>They currently are using MS Excel/Outlook and they copy and paste the row into an email that they can use their contacts to select from. If I cannot get the function to use Googles Contacts, I was considering creating a sheet of drivers with a look up function or something - kind of a pain to have to keep a list when contacts are right there - but ya do what ya gotta do!</p>