简体   繁体   English

为什么某些由带有表单提交触发器的 Google Apps 脚本发送的电子邮件会发送两次?

[英]Why some of emails which sent by Google Apps Script with Form-submission trigger send twice?

I've noticed my sent email from Google App Script with Form-Submission Triggered and found that 3 in almost 300 of my emails are sent twice.我注意到我从 Google App Script 发送的 email 触发了表单提交,发现我的近 300 封电子邮件中有 3 封被发送了两次。 I have no idea about this and here is what i wrote.我对此一无所知,这就是我写的。


function emailAsExcel(spreadsheetId,subject,message,fileName,link) {

  var ss = SpreadsheetApp.openById(spreadsheetId);
  var fileId = ss.getId();
  var data = ss.getActiveSheet().getRange('A2:D2').getValues();

  var url           = 'https://docs.google.com/spreadsheets/d/'+fileId+'/export?format=xlsx';
  var token         = ScriptApp.getOAuthToken();
  var response      = UrlFetchApp.fetch(url, {
    headers: {
      'Authorization': 'Bearer ' +  token
    }
  })
  var blobs   =  response.getBlob().setName(fileName+'.xlsx');

  var picblobs = DriveApp.getFileById(getIdFromUrl(link)).getBlob().setName(fileName + '.jpg');

  var sender = "xxx@gmail.com"+","+ "yyy@gmail.com";

  var email = sender;

  MailApp.sendEmail(email,subject,message,{attachments: [blobs, picblobs]});  

}

function genFile(){

  var ss = SpreadsheetApp.openById('xxxxxxxxxxxx');
  var sheet = ss.getSheetByName('yyyyy');

  var lastRow = sheet.getRange(1,9,sheet.getLastRow()).getValues().filter(String).length;
  Logger.log(lastRow);
  var date = sheet.getRange('A'+lastRow).getValue();
  var name = sheet.getRange('J'+lastRow).getValue();
  var surname = sheet.getRange('K'+lastRow).getValue();
  var number = sheet.getRange('E'+lastRow).getValue();
  var prov = sheet.getRange('F'+lastRow).getValue();
  var brand = sheet.getRange('G'+lastRow).getValue();
  var link = sheet.getRange('I'+lastRow).getValue();  

  var subject = name+'_'+surname;

  var message = 
      'customer fullname : '+ name +' '+surname+'\n'
      +'num : '+ number + prov+'\n'
      +'bra : '+ brand +'\n'

  var fileName = name+ ' ' +surname;
  Logger.log(link); 

  var destination = DriveApp.getFileById('aaaaaaaaaaaaaaaa').makeCopy().getId();
  var newFile = SpreadsheetApp.openById(destination);
  var newSheet = newFile.getSheetByName('bbbbbbbbb');

  newSheet.getRange('A2').setValue(date);
  newSheet.getRange('B2').setValue(name+' '+surname);
  newSheet.getRange('C2').setValue(number);
  newSheet.getRange('D2').setValue(prov);
  newSheet.getRange('E2').setValue(brand);
  newFile.setName(fileName);

  emailAsExcel(destination,subject,message,fileName,link);

}

function getIdFromUrl(url) { return url.match(/[-\w]{25,}/); }
  genFile();
}

I try to figure it out but I still do not know what happened, so I need you guys' advice.我试图弄清楚,但我仍然不知道发生了什么,所以我需要你们的建议。 Thank you in advance!先感谢您!

This likely happens when you (or another Google account that has access to this script) has created multiple triggers.当您(或有权访问此脚本的其他 Google 帐户)创建了多个触发器时,可能会发生这种情况。

Go to https://script.google.com/home/triggers , choose your project and remove any duplicate onSubmit triggers. Go 到https://script.google.com/home/triggers ,选择您的项目并删除任何重复的 onSubmit 触发器。

暂无
暂无

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

相关问题 基于 Google 表单提交发送的多封条件电子邮件 - Multiple conditional emails sent based on Google Form submission Google Apps脚本-拒绝表单提交 - Google Apps Script - reject form submission Google 表单根据复选框问题的答案发送电子邮件,允许多选项提交 - Google Form send emails based on answer of checkbox question which allows for multi-option submission 使用Google Apps脚本解析表单提交 - Parse Form Submission with Google Apps Script 在不提交表单的情况下触发 Google 脚本 - Trigger Google script without Form submission 我的Google Apps脚本在提交表单后发送电子邮件未处理基础电子表格中的数组公式 - My google apps script to send email after a form submission is not handling an array formula in the underlying spreadsheet 使用 Google Apps 脚本发送的 G Suite 电子邮件未发送“邮件已阻止” - G Suite Emails Sent with Google Apps Script Are Not Delivered "Message Blocked" 脚本在谷歌表单提交触发器上运行两次 - Script runs twice on google form submit trigger 使用 Google Apps 脚本发送带有 .xlsx 附件的电子邮件(100 个附件作为 100 个单独的电子邮件发送到一个电子邮件地址) - Send email with .xlsx attachment using Google Apps Script (100 attachments sent as 100 separate emails to one email address) Google Apps脚本:已提交的邮件内容(表单提交脚本) - Google Apps Script: Message Content As Is submitted (Form Submission Script)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM