将多个附件添加到电子邮件

问题描述:

我有一个脚本,它生成一个文档,保存为PDF并附加到电子邮件。除了这个附件之外,我正在尝试添加第二个附件,它是保存在Google Drive(条款)上的现有PDF。为什么下面的代码不附加第二个文档?将多个附件添加到电子邮件

if (email_status == "YES") { 
    //send a pdf copy to customer 
    var pdfEMAIL = DriveApp.getFileById(doc.getId()).getAs('application/pdf').getBytes(); 
    var terms = DriveApp.getFileById('file ID'); 
    var message = "Hi " + usernamefordoctitle + "!, please kindly find your invoice attached.\nMany Thanks!\nMe"; 
    var emailAdd = sheet.getRange("D2").getValue() 
    var emailTo = emailAdd; // add customer email here 
    var subject = "Invoice for " + usernamefordoctitle + " from ME" + " - Invoice Number : " + newInvNumber; 

    var attach = {fileName:"INVOICE " + newInvNumber + " " + usernamefordoctitle + '.pdf',content:pdfEMAIL, mimeType:'application/pdf'}; 

    MailApp.sendEmail(emailTo, subject, message, {attachments:[attach, terms.next()]}); 
    ss.toast("70%: emailed customer"); 
    Utilities.sleep(sleepINT); 

    } 

你有

terms = DriveApp.getFileById('file ID'); 

其次

terms.next() 

这是不正确的,因为getFileById让你一个特定的文件与给定的标识。你正在考虑其他方法,如getFilesByName,它返回文件迭代器。该方法的名称是它返回的线索:getFile与getFiles。

所以,简单的连接

{attachments:[attach, terms]} 

会工作。您可能还需要指定MimeType,例如

terms.getAs(MimeType.PDF) 

因此,例如,您将Google文档作为PDF发送。