code:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // 寄信資料開頭於試算表的第二列(第一列是標題欄)
var numRows = 2; // 依據要寄信的份數修改前面的數字
// Fetch the range of cells A2:B3 定義資料範圍
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range. 依每一列的開始取值
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column 資料第一欄-電子郵件
var message = row[1]; // Second column 資料第二欄-內容
var subject = "Sending emails from a Spreadsheet";
MailApp.sendEmail(emailAddress, subject, message);
}
}
沒有留言:
張貼留言