如何解决发送带有附件的Google表格电子邮件ERROR
我想通过电子邮件发送附件,但出现错误
SyntaxError:无效或意外的令牌(第17行,文件“ try.gs”)
我不明白为什么?名为“ i.pdf”的pdf文件在我的Google驱动器中
这是我的代码:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // Start at second row because the first row contains the data labels
var numRows = 3; // Put in here the number of rows you want to process
// Fetch the range of cells A3:E3
// Column A = Name,Column B = Email,Column C = Message,Column D = Message1,Column E = Message2
var dataRange = sheet.getRange(startRow,1,numRows,4)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[2]; // First column of selected data
var message = "Hey "; // Assemble the body text
var subject = "Sending emails from a Spreadsheet";
var file = DriveApp.getFilesByName(‘i.pdf’);
if (file.hasNext())
MailApp.sendEmail(emailAddress,subject,message,{
attachments: [file.next().getAs(MimeType.PDF)],name: ‘Simple mail’});
}
}
有人可以帮我吗
解决方法
该错误是由印刷/大写/单引号字符= ‘’
引起的。
用单引号或双引号字符''
或""
代替。
相关
- Notify via email when a cell is updated in google spreadsheet
- Google AppScript syntax error for sendemail. Can't ID my problem
在声明var file
时和在MailApp.sendEmail()
函数中,您有两种错别字。尝试以下方法:
function sendEmails() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // Start at second row because the first row contains the data labels
var numRows = 3; // Put in here the number of rows you want to process
// Fetch the range of cells A3:E3
// Column A = Name,Column B = Email,Column C = Message,Column D = Message1,Column E = Message2
var dataRange = sheet.getRange(startRow,1,numRows,4)
// Fetch values for each row in the Range.
var data = dataRange.getValues();
for (i in data) {
var row = data[i];
var emailAddress = row[2]; // First column of selected data
var message = "Hey "; // Assemble the body text
var subject = "Sending emails from a Spreadsheet";
var file = DriveApp.getFilesByName("i.pdf");
if (file.hasNext())
MailApp.sendEmail(emailAddress,subject,message,{
attachments: [file.next().getAs(MimeType.PDF)],name: "Simple mail"});
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。