Google apps script 谷歌应用程序脚本通过电子表格发送电子邮件
我正在尝试创建一个谷歌应用程序脚本,可以为我发送电子邮件,我有点卡住了。我到处找都没找到。我希望这样做的方式是发送一封电子邮件,其中包含一个永不更改的CC'd列表,并让bcc变量引用电子表格上的一列,因为该列每周都会更改 任何帮助都将不胜感激。我下面的尝试产生错误,因为第15行和第16行不正确Google apps script 谷歌应用程序脚本通过电子表格发送电子邮件,google-apps-script,google-sheets,gmail-api,Google Apps Script,Google Sheets,Gmail Api,我正在尝试创建一个谷歌应用程序脚本,可以为我发送电子邮件,我有点卡住了。我到处找都没找到。我希望这样做的方式是发送一封电子邮件,其中包含一个永不更改的CC'd列表,并让bcc变量引用电子表格上的一列,因为该列每周都会更改 任何帮助都将不胜感激。我下面的尝试产生错误,因为第15行和第16行不正确 function sendEmails() { var sheet = SpreadsheetApp.getActiveSheet() var startRow = 2; // First row o
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet()
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:C
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, includes Will.Henderson.
var message = 'test';
var subject = 'testy pants'
var options = {
cc = row[1]; // Second column is the listserv that never changes. You mad add folks here on occasion
bcc = row[2]; // Third column include managers that change each week to bcc
}
MailApp.sendEmail(emailAddress, subject, message);
}
}
您可以尝试以下方法:
MailApp.sendEmail('mike@example.com', 'Subject', 'Your body.', {
bcc:'email/s',
cc:'email/s'
});
解释:你非常接近。json对象
选项的定义如下:
var options = {
cc : row[1], // Second column is the listserv that never changes. You mad add folks here on occasion
bcc : row[2] // Third column include managers that change each week to bcc
}
MailApp.sendEmail(emailAddress, subject, message, options);
然后你可以这样发送电子邮件:
var options = {
cc : row[1], // Second column is the listserv that never changes. You mad add folks here on occasion
bcc : row[2] // Third column include managers that change each week to bcc
}
MailApp.sendEmail(emailAddress, subject, message, options);
完整解决方案: