我有一个Google表单,其中我收到了收件人的电子邮件"电子邮件"和#34;摄入号码"作为输入。
我尝试将脚本编写为在表单提交时运行,以便在Google云端硬盘中搜索"进入号码"作为文件夹名称,并将该文件夹中的所有项目作为电子邮件中的附件发送给收件人的电子邮件。我已经弄明白了如何发送单个附件(基于文件ID),但我想从用户选择的特定文件夹中发送多个附件。这可能吗?
这是我迄今为止所做的,但代码一直与getFolderByName绑定
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2;
var numRows = 3;
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var intakenumber = row[1];
var emailaddress = row[2];
}
var files =
DriveApp.getFolderByName(intakenumber).getFilesByType(MimeType.PDF);
var attachments = [];
while (files.hasNext()) {
var file = files.next();
attachments.push(file.getAs(MimeType.PDF));
Logger.log(attachments)
var message = "document attached";
var subject = "test";
var attachment = (attachments)
MailApp.sendEmail({
to: emailaddress,
subject: subject,
htmlBody: message,
attachments: attachments
})
}
}