Make Google Apps Script handle email client configuration

40 Views Asked by At

I have this Google Apps script to handle Adobe Acrobat Pro DC Form. The idea is to fill out the Adobe form and click on submit, once button click it should send complete adobe form as PDF The Complete document.

function doPost(e) {
  try {
    console.log('Event Object: ', JSON.stringify(e));

    if (!e || !e.postData || !e.postData.contents) {
      throw new Error("No post data received");
    }

    var fileBlob = Utilities.newBlob(e.postData.contents, 'application/pdf', 'Form Submission.pdf');

    // To email the PDF file
    MailApp.sendEmail({
      to: "[email protected]",
      subject: "Form Submission",
      body: "Please find the attached filled form.",
      attachments: [fileBlob]
    });

    // To upload the PDF file to Google Drive
    var folder = DriveApp.getFolderById('Google Drive ID');
    folder.createFile(fileBlob);

    return ContentService.createTextOutput(JSON.stringify({ result: 'success' }))
                         .setMimeType(ContentService.MimeType.JSON);
  } catch (error) {
    console.error(error);
    return ContentService.createTextOutput(JSON.stringify({ result: 'error', message: error.message }))
                         .setMimeType(ContentService.MimeType.JSON);
  }
}

I am getting this error :

An error occurred during the submit process. Cannot process content of type application/json; charset=utf-8.

Even though if I changed application/json, it does not help.

Basically, we have an Adobe form to be submitted by the customers after it is filled. It works fine if we put "Enter URL: mailto:[email protected]" Unfortunately it requires an email client to be installed on customer machines, which is impossible to tell customers to configure an email client on their machine before submitting the form. Therefore, I want Google Apps Script to handle that for me.

0

There are 0 best solutions below