我已经检查了她的大部分可用资源,但仍然在跟随:
我'手动'设置在设置中定义的工作表中的值: 例如SampleEmail; 值是选项1,选项2,选项3, 而电子邮件别名我保留在Settings.sheet
中所以我想发送匹配的电子邮件(在Run.Trigger上) 例如,如果SampleEmail.Sheet中的选项1然后使用Settings.Sheet选项1发送电子邮件关联EmailAdress
function sendEmail() {
var settingsSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("BugSettings");
var mainSheetName = settingsSheet.getRange("B1").getValue();
var mainSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(mainSheetName);
var lastRow = mainSheet.getLastRow();
var lastRowSet = settingsSheet.getLastRow();
var startRow = settingsSheet.getRange("B2").getValue();
for (i = 0; i < lastRow - 1; i++) {
var currentRow = i + startRow;
var isEmailSent = mainSheet.getRange("K" + currentRow).getValue();
var componentName = mainSheet.getRange("A" + currentRow).getValue();
var recipient = settingsSheet.getRange("A" + lastRowSet).getValue();
var emails = settingsSheet.getRange("B" + lastRow).getValue();
var email = ''; // If we don't find a match, we'll fail the send
for (var row = 0; row < componentName.length; row++) {
if (componentName[row][0] == recipient) {
email = emails[row][0];
if (isEmailSent == "") {
var owner = "OWNER: " + mainSheet.getRange("B" + currentRow).getValue();
var milestone = "MILESTONE: " + mainSheet.getRange("C" + currentRow).getValue();
var sourceDoc = "SOURCE DOCUMENT: " + settingsSheet.getRange("B5").getValue();
var dateAdded = "DATE ADDED: " + mainSheet.getRange("G" + currentRow).getValue();
var message = "<P>" + owner + "," + "<P>" + milestone + "," + "<P>" + sourceDoc + "," + "<P>" + dateAdded + ","
var subjectMilestone = mainSheet.getRange("C" + currentRow).getValue();
var subjectAI = mainSheet.getRange("D" + currentRow).getValue();
var subject = [subjectMilestone + subjectAI];
MailApp.sendEmail(email, subject, "", {
htmlBody: message,
name: "My Name"
});
mainSheet.getRange("K" + currentRow).setValue("Yes");
}
}
}
}
}