有2个或更多图纸失败发送工作表作为电子邮件中的附件

时间:2018-03-27 12:11:49

标签: email google-apps-script google-sheets google-drive-api

我有一个脚本通过电子邮件将表格作为PDF附件发送。

extra text

过去常常会工作到一周左右。现在我收到错误: 我们很抱歉,发生了服务器错误。请稍等一下再试一次。 (第66行,文件" FeedbackEmail")。这一行是:

function fdbkEmail() {

  // Set the Active Spreadsheet
  var originalSpreadsheet = SpreadsheetApp.getActive();

  // Set the Sheet you want to email
  var sourcesheet = originalSpreadsheet.getSheetByName("Feedback");

  // Range to get (Does not work, Emails the entire sheet)
  var sourcerange = sourcesheet.getRange('A1:M54');

  var sourcevalues = sourcerange.getValues();

  var data = sourcesheet.getDataRange().getValues();

  // The email senders name is fetched to display in the end of the email body (Generally the PM's Name)
  var emailsendername = originalSpreadsheet.getRange("BackEnd!B2").getValue();

  // The name of the person who the feedback was for
  var feedbackreciever = originalSpreadsheet.getSheetByName("Feedback").getRange('D1').getValue();

  // Name of the Project to be defined
  var projectname = originalSpreadsheet.getSheetByName("Feedback").getRange('I1').getValue();

  // Set the message to attach to the email.
  var message = 'Hi,' + '\n' + '\n Please find attached PDF document of the feedback provided to ' + feedbackreciever + '\n' + '\nRevert for any clarifications.' + '\n' + '\n' + '\nRegards!' + '\n' + emailsendername;

  // Construct the Subject Line
  var subject = projectname + ' | Feedback | ' + feedbackreciever;

  var backEndSheet = originalSpreadsheet.getSheetByName("BackEnd");

  // Request for additional Recipient Email Address
  var addRecp = Browser.inputBox('Add Recipients?', 'Enter email addresses seperating each by a comma and followed by a space (, )', Browser.Buttons.OK_CANCEL);
  if (addRecp == "cancel") {
    return;
  }
  backEndSheet.getRange('F2').setValue(addRecp);

  var emailAdd = backEndSheet.getRange('F2').getValues().toString();

  // Google scripts can't export just one Sheet from a Spreadsheet
  // Create a new Spreadsheet and copy the current sheet data range into it.
  var newSpreadsheet = SpreadsheetApp.create("Temp Feedback"); // can give any name.
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A1:M54").getValues();

  var sheet = sourcesheet.copyTo(newSpreadsheet);
  var destrange = sheet.getRange('A1:M54');
  destrange.setValues(sourcevalues);
  newSpreadsheet.getSheetByName('Sheet1').activate();
  newSpreadsheet.deleteActiveSheet();

  // Make PDF, currently called "Planning Poker Estimates"
  var pdf = DriveApp.getFileById(newSpreadsheet.getId());
  var theBlob = pdf.getBlob().getAs('application/pdf').setName(subject + ".pdf");

  // Delete the wasted sheet we created, so our Drive stays tidy.
  DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);

  // Send the freshly constructed email (This is the line Error Occurs) 
  MailApp.sendEmail(emailAdd, subject, message, {attachments: [theBlob]});

  //Show a Pop-Up message on Email Confirmation
  {
    Browser.msgBox('Email Sent', 'A PDF Copy of the Feedback has been sent successfully to : ' + emailAdd, Browser.Buttons.OK);
  }
}

在我的故障排除过程中进行了以下观察:

  1. 没有图纸和/或只有一张图纸就可以了。工作表上有多个绘图(简单按钮图纸)会导致错误随机发生
  2. 有3个或更多图纸会导致错误发生90%的时间。当在图纸上移动图纸以确保它们不会落在同一列下时,脚本会发送电子邮件,但仅限于此时。几分钟后重新尝试发送会再次导致错误。
  3. 如果按钮图纸超过4,则始终无法发送电子邮件
  4. 我在

    上尝试过排查
    • 不同的浏览器
    • 不同的网络连接
    • 在不同的计算机上(Win 7 OS,Chrome浏览器)
    • 我没有记住的Windows操作系统,防病毒软件或相关软件更新

    我不明白这个的原因。我做错了什么或遗失了什么?

    印张:

    Sample Sheet

    SCRIPT:

    my_obj.child_object = mock.Mock()
    my_obj.child_object.meth1_call = mock.Mock()
    my_obj.child_object.meth1_call().meth2_call = mock.Mock(return_value= [custom_list])
    

0 个答案:

没有答案