Google 应用脚本未通过触发器发送自动电子邮件

Google App Script not sending auto Email via Trigger

我一直在尝试通过 Google 应用程序脚本发送自动电子邮件。有两个相似的脚本,但有两个不同

电子邮件文本 电子邮件正文 主题

我还设置了一个触发器,在编辑时发送自动电子邮件,当 Col"E 中有"Different" 值时,脚本会发送电子邮件“。 (脚本名称是 2nd_Email)

我只希望如果“New Request”值出现在 Col"E" 中,那么 1st_Email 应遵循脚本。

我已经尝试过,但有时 1st_Email 脚本有效,有时 2nd_Email 有效。

我希望它们都根据 Col"E" 值工作。

请访问sheet。 https://docs.google.com/spreadsheets/d/1Eu-c5CPj6XKQSAkSumuprA41-Cx_jvOuUPHr9Zg8KyQ/edit#gid=797418690

只为 First_email 函数保留触发器,并将第二个代码添加到第一个代码中作为 if 条件的替代。

function First_email() { 

  var INITIALline = 2; 
  var columnSEND = 5;  
  var STATUScolumn = 16;
  var textCONDITION = "New Request";
  var textCONDITION2 = "Different";
  var textSENT = "Mail_Sent"
    
  var tab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data"); 
  var interval = tab.getRange(INITIALline,1,tab.getLastRow()-INITIALline+1,STATUScolumn);
  var dice = interval.getValues();
  var yousent = false;
  var email,subject,message;
  
  for (var i=0; i<dice.length; ++i) {
    if((dice[i][columnSEND-1]==textCONDITION) && (dice[i][STATUScolumn-1]!=textSENT)){
    
      var email    = dice[i][9]
    
      subject = dice[i][6]+" | New Request | "+dice[i][0];
            
      var message = "<font size='3' face='Comfortaa'>Dear Different "+dice[i][6]+",<br/><br/>"+
      
                     "Thanks for New Request with us."+dice[i][0]+".<br/><br/>"+
                     
                     "<i>Thanks & Regards</i><br/>"+
                     "<b> New Request </b>";
      
      MailApp.sendEmail(email, subject, message,{ htmlBody: message});
      tab.getRange(INITIALline+i,STATUScolumn).setValue(textSENT);
      yousent = true;
      SpreadsheetApp.flush();
    }
    
     else if((dice[i][columnSEND-1]==textCONDITION2) && (dice[i][STATUScolumn-1]!=textSENT)){
    
      var email    = dice[i][9]
    
      subject = dice[i][6]+" | Different | "+dice[i][0];
            
      var message = "<font size='3' face='Comfortaa'>Dear "+dice[i][6]+",<br/><br/>"+
      
                     "Thanks for Different with us."+dice[i][0]+".<br/><br/>"+
                     
                     "<i>Thanks & Regards</i><br/>"+
                     "<b> Different </b>";
      
      MailApp.sendEmail(email, subject, message,{ htmlBody: message});
      tab.getRange(INITIALline+i,STATUScolumn).setValue(textSENT);
      yousent = true;
      SpreadsheetApp.flush();
    }
     
  }
 }