使用sendEmail,我怎樣才能通過組合兩個表單域來發送郵件給多個逗號分隔的收件人?當(lastrow,4)只有一個值([email protected])但不超過一個時([email protected],[email protected]),似乎可行。當前的代碼在下面,並且所討論的變量是收件人到。Google Apps腳本sendEmail:多個收件人字符串?
function FormEmail() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheetform = ss.getSheetByName("Sheet1"); // Name of the sheet which contains the results
var lastrow = sheetform.getLastRow();
var recipientsTO = sheetform.getRange(lastrow,3).getValue() + "@domain.com";
var recipientsCC = ""
var team = sheetform.getRange(lastrow,5).getValue();
var datestamp = Utilities.formatDate(sheetform.getRange(lastrow,1).getValue(), "GMT - 5", "yyyy-MM-dd");
var html = "Intro text;
//The questions order in the email will be the order of the column in the sheet
for (var i = 2; i < 11; ++i) {
html = html + "<b>" + sheetform.getRange(1,i).getValue() + "</b><br>";
html = html + sheetform.getRange(lastrow,i).getValue() + "</p><br>";
}
//Add additional emails if entered in form field
if (sheetform.getRange(lastrow,4).getValue() !== "") {
recipientsTO = recipientsTO + "," + sheetform.getRange(lastrow,4).getValue()
}
//CC if response to a question is "Yes"
if (sheetform.getRange(lastrow,10).getValue() == "Yes") {
recipientsCC = "[email protected]"
}
MailApp.sendEmail({
to: recipientsTO,
cc: recipientsCC,
subject: "Subject",
htmlBody: html,
});
}
您可以嘗試在添加其他電子郵件地址的if語句正下方添加Logger.log(recipientsTO),然後查看日誌以查看是否可以看到任何格式不正確的addesses。 – ScampMichael 2013-05-02 18:31:39