Gmail应用程序脚本:基于Google Drive URL的附件
我正在使用我在此处找到的邮件合并脚本,但是我很难找到适合附加文件的类(第14和15行)。
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow, 1, numRows, 1)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[3]; // First column
var message = row[10]; // Second column
var subject = row[6];
var attachment = Attachment.setUrl(row[11]);
MailApp.sendEmail(emailAddress, subject, message, {attachments: attachment});
}
}
我已经尝试了几种附件功能的变体,但是每次都遇到了错误。行对应于Google表中的列,而行[11]是Google Drive中图像的URL。
I am using a mail merger script I found here, but I'm having trouble finding the right class to attach the file (rows 14 and 15).
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = 1; // Number of rows to process
// Fetch the range of cells A2:B2
var dataRange = sheet.getRange(startRow, 1, numRows, 1)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[3]; // First column
var message = row[10]; // Second column
var subject = row[6];
var attachment = Attachment.setUrl(row[11]);
MailApp.sendEmail(emailAddress, subject, message, {attachments: attachment});
}
}
I've tried a handful of variations for the attachment function, but I've gotten an error each time. The rows correspond to columns in a Google Sheet, and row[11] is the URL for an image in google drive.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您脚本的一个工作示例:您有2个错误:
也应该是blobs的数组,即url必须有效,并且文件必须公开共享:示例:示例:
here is a working example of your script : you had 2 errors :
note also that url must be valid and that the file must be publicly shared : example :
与Serge Insas的答案类似,这是我必须要做的才能绕过401错误时使用urlfetchapp.fetch
Similar to Serge insas's answer, this is what I had to do in order to bypass the 401 error when using UrlFetchApp.fetch