使用Google Script自动发送电子邮件

时间:2017-07-22 11:54:41

标签: google-sheets javamail

我有数据

日期(不匹配的广告请求)匿名品牌的总票数
01-07-2017 0 59 50 100
02-07-2017 19580 4602 6975 31157
03-07-2017 20924 4843 7620 33387
04-07-2017 22686 3894 6186 32766
05-07-2017 23015 3476 4902 31393
06-07-2017 24108 3812 5001 32921

function sendEmail() {

var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;  // First row of data to process
var numRows = 50;   // Number of rows to process

var dataRange = sheet.getRange(startRow, 1, numRows, 50);

// Fetch values for each row in the Range.
var data = dataRange.getValues();
//Browser.msgBox(data)

for (i in data) {
var row = data[i];
{
  var emailAddress = row[5];  // First column
  var message = row[2];       // Second column
  var subject = "Sending emails from a Spreadsheet";
  MailApp.sendEmail(emailAddress, subject, message);
 // Browser.msgBox(emailAddress)

}

}

}

你能帮我用谷歌脚本发送整个数据吗

1 个答案:

答案 0 :(得分:0)

function sendEmail() 
{
  var sheet = SpreadsheetApp.getActiveSheet();
  var dataRange = sheet.getDataRange()
  var data=dataRange.getValues();
  for (var i=1;i<data.length;i++) 
  {
    var emailAddress = data[i][0];  // First column
    var message = data[i][1];       // Second column
    var subject = "Sending emails from a Spreadsheet";
    MailApp.sendEmail(emailAddress, subject, message);
  }
}