javascript - 截至上周,Google 文档邮件合并脚本无法正常工作

标签 javascript google-apps-script google-sheets google-docs

我们用于 5 个 Google 文档的邮件合并脚本上周停止工作 - 几周前发生了类似的事情,当时 DocsList 已过时,我能够修复它,但现在它又停止工作了。

var docTemplate = "15kvC3M8b0Me3Vi3GwErQvG60BlTC0qAHMXrlc3Ocky8";  
var docName     = "RefundByCheck"

function onFormSubmit(e) { 
   var first_name = e.values[1];
   var last_name = e.values[2];
   var customer_email = e.values[3];
   var brand = e.values[4];
   var amount = e.values[5];
   var purchase_date = e.values[6];
   var customer_address = e.values[7];
   var rep_name = e.values[8];
   var order_number = e.values[9];
   var copyId = DriveApp.getFileById(docTemplate)
                .makeCopy(docName+'_'+order_number)
                .getId();
   var copyDoc = DocumentApp.openById(copyId);
   var copyBody = copyDoc.getActiveSection();
   copyBody.replaceText('keyFirst', first_name);
   copyBody.replaceText('keyLast', last_name);
   copyBody.replaceText('keyBrand', brand);
   copyBody.replaceText('keyAmount', amount);
   copyBody.replaceText('keyPurchaseDate', purchase_date);
   copyBody.replaceText('keyAddress', customer_address);
   copyBody.replaceText('keyRep', rep_name);
   copyBody.replaceText('keyOrder', order_number);
   var todaysDate = Utilities.formatDate(new Date(), "GMT", "MM/dd/yyyy"); 
   copyBody.replaceText('keyTodaysDate', todaysDate);
   copyDoc.saveAndClose();
   var pdf = DriveApp.getFileById(copyId);
   var theblob = pdf.getBlob().getAs('application/pdf');
   var folder = DriveApp.getFolderById('0B3nrCN8N5OBcRnlWaUlHZUxZNE0');
   var movefile = folder.createFile(theblob);
   DriveApp.removeFile(movefile);
   var subject = "Text goes here" + order_number
   var body    = "Hello " + first_name + " " + last_name + "," + "<br /><br />" 
   + "Text goes here" + "<br /><br />"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   + "Text goes here"
   var cc = "test@test.com";
   MailApp.sendEmail(customer_email, subject, body, {htmlBody: body, attachments: pdf, cc: cc}); 
   DriveApp.getFileById(copyId).setTrashed(true);
}

我有一种感觉,Google 更新了其他内容,我需要更改我的代码,但我不确定 - 由于我收到的失败通知摘要,我很确定本节中的某些内容已损坏:5/25/15 8:59 AM onFormSubmit 很抱歉,当前没有可用的服务器。请稍等一下,然后重试。(第 41 行,文件“RefundByCheckCode”)

   var movefile = folder.createFile(theblob);

有什么想法或建议吗?

最佳答案

这似乎是Issue 3206 ,“发送带有绘图附件(PDF 格式)的邮件始终失败”。访问该缺陷并为其加注星标以获取更新。您的脚本中似乎没有新的场景,但如果您有任何其他信息可以帮助负责解决此问题的 Google 员工,您可以向问题跟踪器添加评论。

由于问题似乎在脚本成功运行一段时间后出现,并且持续存在,因此我建议复制您的脚本,并停用原始脚本。

编辑:OP 能够通过部署模板文件的替换来解决该问题。

关于javascript - 截至上周,Google 文档邮件合并脚本无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30439211/

相关文章:

javascript - 用于游戏开发的 JavaScript 多线程

google-apps-script - 在电子表格列中搜索字符串中的文本,并在另一列中返回结果

javascript - 如何在 Google Apps 脚本中修改 HTMLOutput 之前的 html 文件

javascript - 发送带有附件的Google表格电子邮件ERROR

google-sheets - 谷歌表格 : extract one column of a named range

javascript - Vue.js 可以更新嵌套属性吗?

javascript - 按键模糊功能

javascript - 如何在lodash中进行分组

google-apps-script - 目录查询仅返回 100 个用户

google-sheets - 如何在 Google 表格中使用 importhtml 在同一电子表格中连续导入来自多个 URL 的表格?