【问题标题】:Google Automatic Emails [duplicate]Google 自动电子邮件 [重复]
【发布时间】:2020-09-17 17:40:55
【问题描述】:

代码如下

在发送一些自动电子邮件时遇到问题。我知道如何根据电子表格自动发送电子邮件,但复杂的是需要在交替情况下发送电子邮件。

A 组和 B 组需要每周日收到一封电子邮件,告诉他们本周的日程安排。两组都是面对面或远程,但他们每周交替进行。

即- 本周 A 组亲自到场,而 B 组则偏远。下周他们将对阵(A 组远程,B 组面对面)

对此有什么想法吗?

    function CheckCohortA() 
{
  // Fetch the Cohort
  var CohortRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cohorts").getRange("C2:C8"); 
  var Cohort = CohortRange.getValue();
  
  // Check Cohort
  if (Cohort = "A"){
    // Fetch the email address
    var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cohorts").getRange("B2:B8");
    var emailAddress = emailRange.getValues();
  
  //SendEmail
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // Start at second row because the first row contains the data labels
  var numRows = 10000; // Put in here the number of rows you want to process

  // Fetch the range of cells A2:D
  var dataRange = sheet.getRange("A2:ZZ")
  
  // Fetch values for each row in the Range. I modified this after our call on 4/13 and it no references the cells E and F for th subject and message. 
  // May be easier for Principals to navigate and now this code won't have to be touched as long as the rows aren't changed I don't think. 
  var data = dataRange.getValues();
  for (i in data) {
   var row = data[i];
   var name = row[0];
   var emailAddress = row[1]; 
   var subject = row[5];
   var message = row[4]; 
   var CC = row[3];
   MailApp.sendEmail(emailAddress, subject, message,{
         cc: CC
         });
  }
  }
}

【问题讨论】:

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


    【解决方案1】:

    雷丁if (Cohort = "A"){=simple assignment operator。要进行比较,请使用 =====。参考。 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison

    【讨论】:

    • 嗨鲁本,感谢您的帮助。我不精通Java。您介意解释一下如何使用“==”或“===”进行比较吗?我假设 1 / 2 == 1.0 / 2.0;从文档中意味着 1 和 2 等于 1.0 和 2.0?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-23
    相关资源
    最近更新 更多