Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9782

Error when sending an email with attached PDF using Google Script

$
0
0

It's my first time coding and asking a question here, so I hope I include everything that's needed.

I'm trying to make a code that will create a filled out PDF based off the answers in a Google Form and then email that PDF to the person who filled it out. So far, my PDF is created and I'm able to have the email send, but I keep getting an error when I try to make the PDF attach to the email. The error says "Exception: Invalid argument: attachments" but I'm pretty sure I'm following the correct formatting for what I'm wanting to do. I don't believe it's any issues with permissions. Here's most of what I've done, I've cut out everything that's just dropping info into the PDF.

function afterFormSubmit(e) {  const info = e.namedValues;  const pdfFile = createPDF(info);  sendEmail(e.namedValues['Email Address'][0], pdfFile);}function sendEmail(email, pdfFile) {  GmailApp.sendEmail(email, "subject", "body", {attachments: [pdfFile],},);}function createPDF(info){  const pdfFolder = DriveApp.getFolderById("StringID");  const tempFolder = DriveApp.getFolderById("StringID");  const templateDoc = DriveApp.getFileById("StringID");  const newTempFile = templateDoc.makeCopy(tempFolder);  const openDoc = DocumentApp.openById(newTempFile.getId());  const body = openDoc.getBody();//This is where all the code is for putting info into the PDF.openDoc.saveAndClose();const blobPDF = newTempFile.getAs(MimeType.PDF);const pdfFile = pdfFolder.createFile(blobPDF).setName("StuffAboutNaming");}

I'm at a loss for any other troubleshooting. Any help would be super appreciated. I'm so close to finishing this project.


Viewing all articles
Browse latest Browse all 9782

Trending Articles