Google Docs 邮件合并脚本自上周起无法正常工作

Google Docs Mail Merge script not working as of last week

我们用于 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、"Sending mail with attachment of Drawing (as PDF) consistently fails"。访问该缺陷并为其加注星标以获取更新。您的脚本中似乎没有新场景,但如果您有任何其他信息可能有助于负责解决此问题的 Google 员工,您可以在问题跟踪器中添加评论。

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

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