如何解决在基于应用脚本的邮件合并中附加多个文件动态和静态
我正在尝试将使用草稿的邮件合并代码和使用来自谷歌工作表的数据自动填充谷歌文档的代码结合起来,以生成动态 pdf。只要我注释掉下面的 attachmentList.push(attach2) 行,组合代码就可以工作。 如何合并多个附件?导致此错误的原因是什么?
**给出问题的组合代码片段**
var attachmentList=[];
var docId= generateLetter(row); // generateLetter is the function to fill google doc template with data from google sheet and this is working properly
var attach1 ={fileName:DriveApp.getFileById(docId).getName(),content:DriveApp.getFileById(docId).getAs('application/pdf').getBytes(),mimeType:'application/pdf'}; //convert googledoc to pdf attachment is also working
attachmentList.push(attach1); //this dynamically generated pdf is getting sent in email
var attach2 = {fileName:'Policy.pdf',content: emailTemplate.attachments,mimeType:'application/pdf'}; // this is the inline attachment which by itself is getting sent but not when included in following attachmentList array.
attachmentList.push(attach2); //gives "invalid arguement for attachment" error if this line is uncommented
GmailApp.sendEmail(row[RECIPIENT_COL],msgObj.subject,msgObj.text,{
htmlBody: msgObj.html,attachments: attachmentList,//attachments: emailTemplate.attachments works and so does attachmentList.push(attach1) but if attachmentList.push(attach2) is add it gives invalid arguement error.
inlineImages: emailTemplate.inlineImages
});
解决方法
您需要附件,而不是 json
对象:
var attachmentList=[DriveApp.getFileById(docId).getAs('application/pdf'),emailTemplate.attachments];
GmailApp.sendEmail(row[RECIPIENT_COL],msgObj.subject,msgObj.text,{
htmlBody: msgObj.html,attachments: attachmentList,inlineImages: emailTemplate.inlineImages
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。