I am trying to send an email with an attachment and the URL of the attachment. The email body would look like this:
"Hi Everyone-
Here's the agenda for tomorrow's meeting.
See you in the morning!
-John Doe"
I have written the code to my best ability. I know I wrote the bottom half erroneously. Please assist.
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('[email protected]', 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)] });
}