![](/img/trans.png)
[英]Send email with values for only new rows in a spreadsheet via Apps Script
[英]Google Apps Script Send Email via Spreadsheet
我正在嘗試創建一個 Google 應用程序腳本來為我發送電子郵件,但我有點卡住了。 我四處尋找無濟於事。 我希望這樣做的方法是發送一封電子郵件,其中包含一個永遠不會更改的抄送列表,並讓 bcc 變量引用電子表格上的一列,因為每周都會更改。
任何幫助將非常感激。 我在下面的嘗試會產生錯誤,因為第 15 16 行不正確。
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);
}
}
解釋:你很親近。 json 對象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);
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, options);
}
}
你可以試試這個:
MailApp.sendEmail('mike@example.com', 'Subject', 'Your body.', {
bcc:'email/s',
cc:'email/s'
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.