I am trying to generate a draft email on a spreadsheet using Google Scripts. Everything works perfectly fine for generating the PDF (I can see it in my drive folder), and generating the draft email (I can see it in my drafts), but the attachment is not being added to the draft without throwing any errors.
This is the code:
function CreateDraft(invoiceSheet, pdfFile) {
var email = invoiceSheet.getRange(emailRange).getValue().toString();
var subject = invoiceSheet.getRange(subjectRange).getValue().toString();
var body = BuildBodyMessage(invoiceSheet.getRange(bodyRange).getValues());
GmailApp.setCurrentMessageAccessToken(ScriptApp.getOAuthToken());
var gmailDraft = GmailApp.createDraft(email, subject, body, [{
attachments: [pdfFile.getAs(MimeType.PDF)]
}]);
OpenTab(gmailDraft.getMessageId().toString());
}
What is wrong with it? I have checked many websites and stackoverflow answers and it seems to be correct. Are there any other ways to generate drafts with attachments without using GmailApp? Maybe some advance service?
Aucun commentaire:
Enregistrer un commentaire