I am trying to send an email automatically via Google Sheets with an attachment such as XLSX or Sheets version but I cannot. I have the following error message:
Exception: Converting from application/pdf to application/vnd.google-apps.spreadsheet is not supported. SendAttachment @ Send Email.gs:9
function sendReport() {
var message = {
to: "youremail@example.com",
subject: "Monthly sales report",
body: "Hi team,\n\nPlease find the monthly report attached.\n\nThank you,\nBob",
name: "Bob",
attachments: [SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.GOOGLE_SHEETS).setName("Monthly sales report")]
}
MailApp.sendEmail(message);
}
Also, is this possible to choose which cell will be show on the attachment ? I don't know how to do this.
Thank you for your help,
Have a nice day :)