向gmail添加多个附件



我使用的是谷歌电子表格,希望向我们的客户发送多个附件,无论我如何格式化代码,它要么被拒绝,要么只发送了一个附件,有人能帮忙吗?

function emailcustomer() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("email to customer")  
var subject = sheet.getRange("B2").getValue()
var content = sheet.getRange("A12").getValue()
var doc1 = sheet.getRange("d28").getValue()
var doc2 = sheet.getRange("d29").getValue()   
var file1 = DocsList.getFileById(doc1);  
var file2 = DocsList.getFileById(doc2); 
  GmailApp.sendEmail("alex.shaw94@gmail.com",subject,content,{attachments:file1 file2});
}

您可以尝试以下操作:

var myFiles = [{fileName:"doc1", content:file1}, {fileName:"doc2", content:file2}]
GmailApp.sendEmail("alex.shaw94@gmail.com", subject,content, {attachments: myFiles});

此外,也许这会有所帮助:https://developers.google.com/apps-script/class_gmailapp#sendEmail

您需要指定附件的mimetype,然后将其添加到您的数组中:

var attachments = [];
attachments.push(file.getAs(MimeType.PDF));
GmailApp.sendEmail(email, subject, body,{
     attachments: attachments,
    });

相关内容

  • 没有找到相关文章

最新更新