我真的很擅长编码。我所知道的一切都是通过研究和YouTube教程完成的。我一直试图弄清楚如何将压缩的zip文件夹附加到我使用Google表格AppsScripts发送到多个电子邮件地址的电子邮件中。
这是我正在使用的代码:
@Model
我不确定
中要做什么 function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 2; // Number of rows to process
// Fetch the range of cells A2:B3
var dataRange = sheet.getRange(startRow, 1, numRows, 2)
// Fetch values for each row in the Range.
var file = DriveApp.getFilesByName('Abs of Steel Workout 002.zip')
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[0]; // First column
var message = "Good morning,\n"
+"\n"
+"Thank you for being with Team Dollar Gains Club! This month is based off super sets. Be sure to follow our social media on Instagram (@DollarGainsClub) and Facebook (facebook.com/dollargainsclub) for inspiration and motivation to kill your workout!\n"
+"\n"
+"Attached to this email are your 2 workout routines and How-To pictures demonstrating the proper technique to perform each exercise. Each routine shall be completed at least once a week for a period of 2 weeks, before moving onto the next routine.\n"
+"\n"
+"If you have any questions about anything, feel free to respond to this email whenever! We are here to help you reach all of your fitness goals. Let's get to it!\n"
+"\n"
+"Best regards,\n"
+"Jordan Taylor\n"
+"Founder of Dollar Gains Club\n"
+"www.dollargainsclub.co";
var subject = "Dollar Gains Club Subscription: Chest Day";
MailApp.sendEmail(emailAddress, subject, message, {attachments: file.next().getBlob()});
}
}
答案 0 :(得分:0)
您似乎有一个名为Abs of Steel Workout 002.zip
的文件要发送给列表中的所有人。命令
var file = DriveApp.getFilesByName('Abs of Steel Workout 002.zip')
不返回文件,而是返回FileIterator,因为Google云端硬盘允许使用同名的多个文件。每次在这个迭代器上调用方法next
时,你会得到其中的下一个文件......但由于你只有一个,所以这会在循环的第二次运行时抛出异常。
因此,next
应该在循环之外调用。而且最好也在那里获得一个blob,因为它对所有消息也是一样的。只需将var file=
替换为
var blob = DriveApp.getFilesByName('Abs of Steel Workout 002.zip').next().getBlob();
在循环中你只需要
MailApp.sendEmail(emailAddress, subject, message, {attachments: blob});