Reputation: 7
I am currently trying to send a Google Sheet as an email attachment using Google Apps Script. When I execute the code (shown below) it automatically sends it as a PDF even though I have not specified I want to send it in this format.
Is there a way to send the attachment in the Google Sheets format?
function emailGoogleSheet()
{
try
{
// Get file from Google Drive
var googleSheet = DriveApp.getFileById("xxxxxxxxxxxxxxxx")
// Send email with file attached
MailApp.sendEmail("[email protected]", "Report", "Please see the attached report.", {attachments: googleSheet})
}
catch (exception)
{
Logger.log(exception);
}
}
Upvotes: 1
Views: 2810
Reputation: 576
the following code will do the work
const file = DriveApp.getFileById("xxxxxxxxxxxxxxxx");
GmailApp.sendEmail(
'email',
'subject',
new_emailbody,
{
htmlBody: new_emailbody,
attachments: [file]
});
Upvotes: 0
Reputation: 26796
This is a regular Blob
contentType
The MIME type to convert to. For most blobs, 'application/pdf' is the only valid option.
Upvotes: 1