I have a PDF and fetch its contents and store it in a Blob. However, I"m not able to attach this blob as an attachment to an email using MailApp.sendEmail() The attachments paramter of options says "files to send in an email. Each item is a JavaScript objects with the following properties: String fileName, String mimeType (optional) and String content."
Although, I can set the mimeType to 'application/pdf', it doesn't work - probably because of the encoding involved. Here is a sample code
var resp = UrlFetchApp.fetch(link);
if (resp.getResponseCode() == 200){
var blob = Utilities.newBlob(resp.getContent());
Logger.log(blob.getDataAsString());
// var pdf = blob.getAs('application/pdf');
var options = {'attachments' :
{'fileName' : 'test',
'mimeType' : 'application/pdf',
'content' : blob.getDataAsString() //Doesn't work
}
};
MailApp.sendEmail(TO_EMAIL, 'Subject','', options);
}