需要帮助添加'n‘的附件数目。
代码如下:
for(var i = 2; i<=lr; i++)
{
var Contact_Person = ss.getRange(i,4).getValue();
var PDFs = ss.getRange(i,6).getValue();
//The above i am grabbing the PDF name from a column in My sheet.
//This name is used for generating my Mail Merge File.
var contents = DriveApp.getFolderById('1ouiQE2cERaRMC_rnSftJCqQCpr2B4x3D').getFiles();
PDFs = DriveApp.getFilesByName(Contractor_Name);
if(PDFs.hasNext())
{
var attach = [];
while(contents.hasNext())
{
var file = contents.next();
if (file.getMimeType() == "application/pdf")
{
attach.push(file);
}
}
GmailApp.sendEmail(currentEmail, Subject, messageBody,
{
attachments: [PDFs.next().getAs(MimeType.PDF), attach[0],attach[1],attach[2], attach[3],],
name: 'Test'
});
}
//This section is for me to grab 1 attachment according to the name specified for that row matching
//the Merged file in the google drive folder.
//I am also trying to attach from a separate folder N number of files to this email.Pdfs是一个变量,用于从电子表格中的第6列获取值。
每行列都有一组名称。
当程序运行时,它执行邮件合并,然后向特定行的用户发送电子邮件。
示例:
Email Subject Reference No. Contact Person Contractor Name PDFs
***@gmail.com Test XXXXX Mr. Dan XYZ Company XYZ Company发布于 2020-10-02 07:28:01
答案:
你可以把它们都推到同一个数组中。
更多资料:
来自GmailApp.sendEmail(recipient, subject, body, options)的文档
高级参数
attachments BlobSource[]与电子邮件一起发送的文件数组
所以你可以把它们都放在一个数组里。
代码片段:
if (PDFs.hasNext()) {
var attach = [];
attach.push(PDFs.next().getAs(MimeType.PDF));
while (contents.hasNext()) {
var file = contents.next();
if (file.getMimeType() == "application/pdf") {
attach.push(file);
}
}
GmailApp.sendEmail(currentEmail, Subject, messageBody, {
attachments: attach,
name: "Test"
});
}参考文献:
https://stackoverflow.com/questions/64165255
复制相似问题