在Google Appscript中抓取具有特定文件名的多个附件 [英] Grabbing multiple attachments with a specific file name in Google Appscript
问题描述
需要有关添加'n'个附件的帮助.
needing help with adding 'n' number of attachments.
以下代码:
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列获取值.
Pdfs is a variable holding getting values from Column 6 in my Spreadsheet.
此行每一行都有一组名称.
This column per row has a set of names.
程序运行时,它将执行邮件合并,然后向特定行的用户发送电子邮件.
When the program runs it performs a mail merge and then sends an email to the user of a specific row.
示例:
Email Subject Reference No. Contact Person Contractor Name PDFs
***@gmail.com Test XXXXX Mr. Dan XYZ Company XYZ Company
非常感谢您的帮助.
谢谢.
推荐答案
答案:
您可以将它们全部推入同一阵列.
从 GmailApp.sendEmail(收件人,主题,正文,选项)
上的文档:
From the documentation on GmailApp.sendEmail(recipient, subject, body, options)
:
高级参数
附件
BlobSource []
与电子邮件一起发送的文件数组
attachments
BlobSource[]
an array of files to send with the email
因此,您可以将它们全部连接到一个阵列中.
So you can attach them all in one array.
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"
});
}
希望对您有帮助!
- Class GmailApp -
sendEmail(recipient, subject, body, options)
| Apps Script | Google Developers
这篇关于在Google Appscript中抓取具有特定文件名的多个附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!