因此,除了我刚刚添加的抄送部分,下面的代码在google appscript中都可以正常工作,问题在代码之后进行了描述
function getSheetID(name){
var ss = SpreadsheetApp.getActive().getSheetByName(name)
var sheetID = ss.getSheetId().toString()
return sheetID
}
function DISCHEMEMAILS() {
//NEWEST PRODUCTS CODE
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCHEM LINES CHECK").activate();
var ssID = SpreadsheetApp.getActiveSpreadsheet().getId();
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
var requestData = {"method": "GET", "headers":{"Authorization":"Bearer "+ScriptApp.getOAuthToken()}};
var shID = getSheetID("DISCHEM LINES CHECK") //Get Sheet ID of sheet name "DISCHEM LINES CHECK"
var url = "https://docs.google.com/spreadsheets/d/"+ ssID + "/export?format=xlsx&id="+ssID+"&gid="+shID;
var result = UrlFetchApp.fetch(url , requestData);
var contents = result.getContent();
//EMAIL ADDRESSES CODE FOR PRIMARY EMAIL
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCHEM EMAILS").activate();
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow,1,numRows,2);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = "Dear"+" "+row[1]+" "+"here are the classifications."; // Second column
var Sheets = [{fileName:sheetName+".xlsx", content:contents, mimeType:"application//xlsx"}]
//EMAIL ADDRESSES CODE FOR BCC EMAIL
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCHEM EMAILS").activate();
var sheet = SpreadsheetApp.getActiveSheet();
var startRowcc = 3; // First row of data to process
var numRowscc = 5; // Number of rows to process
// Fetch the range of cells A3:B7
var dataRangecc = sheet.getRange(startRowcc,1,numRowscc,5);
// Fetch values for each row in the Range.
var datacc = dataRangecc.getValues();
for (var i2 in datacc) {
var rowcc = datacc[i2];
var emailAddresscc = rowcc[0]; // First column
MailApp.sendEmail({
to: emailAddress,
subject: "Classifications",
cc:emailAddresscc,
htmlBody: message,
attachments: Sheets
});
};
};
}
具有为cc发送多封电子邮件的效果,而不是一起发送。它在范围内有三封电子邮件,因此它向我发送一封电子邮件,然后向我发送一封电子邮件,然后向我发送一封电子邮件,然后向我发送2封电子邮件,然后仅向我发送三封电子邮件。主要的。
关于公式的哪一部分我有什么想法?经过更多测试后,我认为这与}的位置有关,但不确定应该在哪里
答案 0 :(得分:0)
因此,我通过直接引用其中包含电子邮件的单元格来进行工作,而不是对主要电子邮件使用相同的代码。哦,它现在可以正常工作。
//cc emails
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCHEM EMAILS").activate();
var cc1 = SpreadsheetApp.getActiveSheet().getRange('A3').getValue();
var cc2 = SpreadsheetApp.getActiveSheet().getRange('A4').getValue();
//EMAIL ADDRESSES CODE FOR PRIMARY EMAIL
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DISCHEM EMAILS").activate();
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow,1,numRows,2);
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (var i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = "Dear"+" "+row[1]+" "+"here are the classifications."; // Second column
var Sheets = [{fileName:sheetName+".xlsx", content:contents, mimeType:"application//xlsx"}]
MailApp.sendEmail({
to: emailAddress,
subject: "Classifications",
htmlBody: message,
cc: cc1 + "," + cc2,
attachments: Sheets
});
};
}