【问题标题】:How do skip blank cells for sending out emails?如何跳过空白单元格发送电子邮件?
【发布时间】:2020-01-27 17:52:45
【问题描述】:

如果学生缺课,我会使用 Google 表单向家长和教练发送电子邮件。我遇到的问题是有时教练的电子邮件没有列出,因为学生没有参加运动,所以它有一个空白单元格,然后脚本将停止运行。我只是希望它跳过并继续向下移动。还有一种方法可以让我得到一个单元格来确认它发送了吗?就像让电子邮件旁边的单元格在失败时说“已发送”或“错误”?我并不真正关心这部分,它会很好。我对此真的很陌生。谢谢!

function SendCoachEmails() {

  SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Homework Hour 4.0").activate();//take off 4.0 when done with texting

  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var lr = ss.getLastRow();
  var templateText = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DO NOT DELETE! Parent Email Template").getRange(1, 1).getValue();
  var quotaLeft = MailApp.getRemainingDailyQuota();

  if((lr-1) > quotaLeft) {
    Browser.msgBox("You have " + quotaLeft + " left and you're trying to send" (lr-1) + " emails. Emails were not sent")
  } else {

    for (var i = 2;i<=lr;i++){  // i is the current row so in this i is row 2 

    var currentEmail = ss.getRange(i,12).getValue(); // 15 is the email column  
    var currentStudent = ss.getRange(i, 4).getValue(); // 4 is student name column
    var currentMessage = ss.getRange(i, 2).getValue(); // 2 is the message column
    var currentMissingAssingment = ss.getRange(i, 9).getValue(); // 9 is the missing assingment column

    var massageBody = templateText.replace("<<Student Name>>",currentStudent).replace("<<Message>>",currentMessage).replace("<<Missing Assingment>>",currentMissingAssingment);
    var subjectLine = currentStudent +" Has Homework Hour"; // change whats in the "" to what you need the subject on the email to be

   MailApp.sendEmail(currentEmail, currentStudent, massageBody); // to change subject on email change "Has Homework Hour" Part//

   } 
  }
 }

【问题讨论】:

    标签: javascript email google-apps-script google-sheets


    【解决方案1】:

    您可以使用简单的条件语句,即在发送之前检查是否有电子邮件

    if (currentEmail.trim() !== '')// check if email is not blank
       MailApp.sendEmail(currentEmail, currentStudent, massageBody); // to change subject on email change "Has Homework Hour" Part//
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 2017-06-19
      相关资源
      最近更新 更多