【发布时间】:2016-12-13 02:00:01
【问题描述】:
我正在尝试发送带有附件和附件 URL 的电子邮件。电子邮件正文如下所示:
“大家好-
这是明天会议的agenda。
早上见!
-John Doe"
我已尽我所能编写代码。我知道我写错了下半部分。请协助。
function sendEmailTest() {
//test send email.
// Send an email with an attachment: a file from Google Drive.
var file = DocumentApp.openById(file2.getId());
var ssUrl = 'URL_BUFFERED';
var sheetName = 'Sheet1'; // name of sheet to use
var rangeName = 'C30'; // range of values to include
var dateRange = SpreadsheetApp.openByUrl(ssUrl)
.getSheetByName(sheetName)
.getRange(rangeName)
.getValues();
// Name of Google file to attach.
var file2 = file.makeCopy('Weekly Agenda | '+dateRange);
// Set Agenda URL.
var theBody = GmailApp.openById(file2.getId()).getBody();
var elementReplaced = theBody.replaceText("%toReplace%", "agendaURL");
elementReplaced.asText().setLinkUrl("https://google.com");
//Send email.
MailApp.sendEmail('who@whowantstoknow.com', file2, 'Hi Everyone- \n Here\'s the ' +agendaURL+'agenda for tomorrow
's meeting. \n See you in the morning! \n-John Doe', {
name: 'Automatic Emailer Script',
attachments: [file.getAs(file2)] });
}
【问题讨论】:
标签: email google-apps-script attachment