Fetch and upload email with attachments to a 3rd party API

18 views
Skip to first unread message

roar.om...@gmail.com

unread,
May 3, 2019, 6:54:27 AM5/3/19
to Google Apps Script Community
Hi All,

I would like get you suggestions on how to overcome the following limitations imposed by Apps script platform in Gmail Addons for achieving my use case mentioned below.

  • Cannot POST data >50MB.
  • Cannot READ a drive file >50MB.
  • Execution time limited to 6s.

Use case


Fetch an email along with attachments and linked drive files and then POST it to a non-google API*. The POST request will also contain a JSON carrying the email metadata. The multipart payload for the API will be like as shown below


payload = meta data + (email + attachments <25MB) + linked drive files

          

*The API does not support any kind of resumable protocol and expects the entire data to be uploaded in one HTTP POST request.

 

Approach for implementing use case

  • Gmail Addon’s contextual handler receives the ID of the email message. This ID is used along with the GmailApp service to retrieve appropriate MessageObject.
  • MessageObject has API to retrieve the metadata.
  • MessageObject.getRawContent gives the email along with attachments <25MB.
  • Parse the raw email body to retrieve the links to the drive files and appropriate file IDs.
  • Use the file ID with DriveApp service to retrieve the file blob and the file content from it.
  • Combine the data to construct the payload.  Supply the payload and make a POST request.
This approach has high potential for running beyond the time limit and crossing the other limitations. What would be the suggested way to achieve the use case while overcoming the limitations?
Reply all
Reply to author
Forward
0 new messages