2017-09-16 96 views
0

我有一個腳本,它生成一個文檔,保存爲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); 

    } 

回答

1

你有

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

其次

terms.next() 

這是不正確的,因爲getFileById讓你一個特定的文件與給定的標識。你正在考慮其他方法,如getFilesByName,它返回文件迭代器。該方法的名稱是它返回的線索:getFile與getFiles。

所以,簡單的連接

{attachments:[attach, terms]} 

會工作。您可能還需要指定MimeType,例如

terms.getAs(MimeType.PDF) 

因此,例如,您將Google文檔作爲PDF發送。