Joseph Eisenreich
Joseph Eisenreich

Reputation: 3

Attempting to Attach a CSV, Converting to PDF

I have a code where I am attempting to attach a CSV saved in Drive (automatically replaced) to an email. At the moment, I can get it to add using fileBlob - DriveApp.getFileById(...).getBlob() but, it's attaching as a PDF.

Per Mogsdad's answer on this question there is a way to attach a CSV, but looking through the documentation I can't seem to find anything that will allow using a CSV. In fact, according to the documentation for getAS() it literally says: "For most blobs, 'application/pdf' is the only valid option. For images in BMP, GIF, JPEG, or PNG format, any of 'image/bmp', 'image/gif', 'image/jpeg', or 'image/png' are also valid."

Does this mean in is impossible to attach a CSV (or, really, anything other than PDF) from Drive to an email using Apps Scripts?

Upvotes: 0

Views: 857

Answers (2)

SUKUMAR S
SUKUMAR S

Reputation: 335

As per following Google Documentation: -

https://developers.google.com/apps-script/reference/base/blob-source.html

Following is mentioned: -

For most blobs, 'application/pdf' is the only valid option.

Following expected work-around: -

https://gist.github.com/nirajkadam/0b41a01b8e739800c964

Upvotes: 0

Amit Agarwal
Amit Agarwal

Reputation: 11268

Assuming the CSV file is in your Drive, you can use this snippet to attach it to an email.

function sendCSV() {
  var blob = DriveApp.getFileById(FILE_ID).getBlob();
  MailApp.sendEmail("[email protected]", "Subject", "CSV", {attachments:[blob]});
}

Upvotes: 1

Related Questions