0

I'm trying to setup a time trigger for the google script to run on a schedule, but I get the following error. I'm trying to run a single script, which has 3 other scripts combined.

All scripts work fine when I manually run it, and emails are triggered without an issue.

Error:

Exception: Invalid email: Internal
    at sendFirstEmail(IntCode:65:13)

Line of Code (there are 3 of these, with few changes in row no., which I combine with "combine" script) - IntCode.gs

function getDataSheet() {

  sheet = SpreadsheetApp.getActiveSheet();

  startRow = 2;  // First row of data to process
  numRows = 200;   // Number of rows to process
  startCol = 1;  //First column of data to process
  numCols = 21;    // Number of columns to process 
  
  var dataRange = sheet.getRange(startRow, startCol, numRows, numCols);

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();  

  return data;  
}

function sendFirstEmail() {
  var complete = "";
  var first = "Yes";
        
  var data = getDataSheet();
  
  for (var i = 0; i < data.length; i++) {
    
    var row = data[i];
    
    var isFirst = row[18];
    var isComplete = row[11];
    var user = row[0];
    var detail = row[1];
    var description = row[2];
    var period = row[3];
    var name_1 = row[4];
    var to_email_1 = row[5];
    var to_email_2 = row[6];
    var cc_email_1 = row[7];
    var cc_email_2 = row[8];
    var cc_email_3 = row[9];
    var email_1 = "email ID";
    var date = row[10];
                
    if(isFirst == first && isComplete == complete ) {
  

      var to_email_1 = row[5];
      var to_email_2 = row[6];
      var cc_email_1 = row[7];
      var cc_email_2 = row[8];
      var cc_email_3 = row[9];
      var email_1 = "[email protected]";
      var period = row[3];
      var message = HtmlService.createHtmlOutputFromFile('FirstMail').getContent();
      var date = Utilities.formatDate( new Date(row[10]), "GMT" , "dd/MMM/yyyy" );
      var file = row[12];
      
      message = message.replace("%user", user);
      message = message.replace("%detail", detail);
      message = message.replace("%description", description);
      message = message.replace("%period", period);
      message = message.replace("%name_1", name_1);
      message = message.replace("%date", date);
      message = message.replace("%file", file);
      
    MailApp.sendEmail({
      name: 'display name',
      to: to_email_1 + ", " + to_email_2,
      replyTo: email_1,
      cc: email_1 + ", " + cc_email_1 + ", " + cc_email_2 + ", " + cc_email_3,
      subject: "[TEST] " + detail + " on " + date,
      htmlBody: message
    });
      
      
    }
  }
}

The combine script (combine.gs) which I'm trying to setup with the time trigger.

function combine() {
 var ss = SpreadsheetApp.openById("google sheet ID");
// https://docs.google.com/spreadsheets/d/id_is_here/
var sh = ss.getSheetByName("Sheet1"); // name of the actual sheet ("Sheet 1" for example)  
  Logger.log('combine ran!');
  sendFirstEmail();
  sendSecondEmail();
  sendFinalEmail();
}
4
  • Which line is 65? And where is sendInitialEmail function? Commented Aug 7, 2020 at 16:54
  • Apologies. Edited the question. Line 65 is MailApp.sendEmail({ Commented Aug 7, 2020 at 16:57
  • AFAICT The email format is invalid. Provide debugging details. See tag info page for "Troubleshooting" Commented Aug 7, 2020 at 17:16
  • Is it the email format or the way the function MailApp.sendEmail is setup? Since I don;'t get this error when triggered manually. And my email format is correct. I'm sorry, I am new to all this so finding it difficult to get this sorted. Commented Aug 7, 2020 at 17:43

1 Answer 1

1

As written in the documentation,

Exception: Invalid email: Internal at sendFirstEmail(IntCode:65:13)

means Internal is not a valid email. Consider tracing back and logging row 5 and 6: console.log(row[5])

Sign up to request clarification or add additional context in comments.

4 Comments

Like this var to_email_1 = row[5]; console.log(row[5]; var to_email_2 = row[6]; console.log(row[6];
So I ran the "Combine" script manually now (which has sendFirstEmail, sendSecondEmail etc.) , it gives the above error. But when I run the "sendFirstEmail" script only I do not get the error message in my question above. Used the console.log(row[5]) too, and it shows the email addresses fine. But there are blank rows in between, in the log.
@Spear Then remove blank rows. Also, Do you have anything in your sheet named "Internal"?
Nothing as internal. Oddly, it started to work now. I only just deleted and pasted the code again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.