简体   繁体   English

试图让 email 脚本与 Google Forms 一起使用

[英]Trying to get a email script working with Google Forms

I am trying to get forms to email certain cells to a specified email.我正在尝试将 forms 到 email 某些单元格到指定的 email。 I have gotten it to email the cells, but it won't email the new rows it just keeps emailing the first row to the email can someone help me with the code so it will email the newly added row and columns I need I have gotten it to email the cells, but it won't email the new rows it just keeps emailing the first row to the email can someone help me with the code so it will email the newly added row and columns I need

function sendEmails() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var startRow = 2; // First row of data to process
  var numRows = 100; // Number of rows to process
  // Fetch the range of cells A2:B3
  var dataRange = sheet.getRange(startRow, 1, numRows, 100);
  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i in data) {
    var row = data[i];
    var emailAddress = 'coryabaird@gmail.com'; // First column
    var message = row[27]; // Second column
    var subject = row[3];
    MailApp.sendEmail(emailAddress, subject, message);
  }
}

Okay here's that tutorial example with an EmailSent column and a couple other changes.好的,这是带有 EmailSent 列和其他一些更改的教程示例。 What else would you like?你还想要什么?

function sendEmails() {
  var sheet=SpreadsheetApp.getActiveSheet();
  var startRow=2; 
  var dataRange=sheet.getRange(startRow, 1, sheet.getLastRow()-startRow+1, sheet.getLastColumn());
  var data=dataRange.getValues();
  for (var i=0;i<data.length;i++) {
    var row=data[i];
    var emailAddress='coryabaird@gmail.com'; // First column
    var message=row[27]; // Second column
    var emailSent=row[?]; // fourth column
    var subject = 'Sending emails from a Spreadsheet';
    if(emailSent!='Sent' && MailApp.getRemainingDailyQuota()>0) {
       MailApp.sendEmail(emailAddress, subject, message);
       sheet.getRange(i+sr,4).setValue('Sent');
    }else{
      SpreadsheetApp.getUi().alert('emailSent: ' + emailSent + ', Quota: ' + MailApp.getRemainingDailyQuota());
    }
  }
}

Image:图片:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM