Send specific PDF attachments from Gmail to Google Drive using OpenAI n8n Workflow Template

n8n workflow template · 11 nodes · OpenAI

Send specific PDF attachments from Gmail to Google Drive using OpenAI is a free n8n workflow template that starts from the Gmail Trigger node and works with OpenAI, Google Drive and Gmail. It has 11 nodes, 1 of them AI nodes (OpenAI). The notes inside the workflow say: “_DISCLAIMER: You may have varying success when using this workflow so be prepared to validate the correctness of OpenAI's results.” To run it, you add your own credentials for Gmail OAuth2, Google Drive OAuth2 and OpenAI API.

At a glance

Trigger
Gmail Trigger (On email received)
Nodes
11
Apps
OpenAI, Google Drive and Gmail
AI nodes
1
Credentials
3 types
Category
Email automation

Apps and integrations

  • OpenAI
  • Google Drive
  • Gmail

Node types used

  • Read PDF
  • Edit Fields (Set)
  • If
  • Code
  • OpenAI
  • Merge
  • Google Drive
  • Gmail Trigger

Setup notes

The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.

Send specific PDF attachments from Gmail to Google Drive using OpenAI

_DISCLAIMER: You may have varying success when using this workflow so be prepared to validate the correctness of OpenAI's results.

This workflow reads PDF textual content and sends the text to OpenAI. Attachments of interest will then be uploaded to a specified Google Drive folder. For example, you may wish to send invoices received from an email to an inbox folder in Google Drive for later processing. This workflow has been designed to easily change the search term to match your needs. See the workflow for more details.

How it works

  1. Triggers off on the On email received node.
  2. Iterates over the attachments in the email.
  3. Uses the OpenAI node to filter out the attachments that do not match the search term set in the Configure node. You could match on various PDF files (i.e. invoice, receipt, or contract).
  4. If the PDF attachment matches the search term, the workflow uses the Google Drive node to upload the PDF attachment to a specific Google Drive folder.

Workflow written by David Sha.

Configuration

Match on(required): What should OpenAI's search term be? Examples: invoice, callsheet, receipt, contract, payslip. Google Drive folder to upload matched PDFs(required): Paste the link of the GDrive folder, an example has been provided but will need to change to a folder you own. maxTokenSize(required): The maximum token size for the model you choose. See possible models from OpenAI here. replyTokenSize(required): The reply's maximum token size. Default is 300. This determines how much text the AI will reply with.

Nodes in this workflow

The 11 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:

  1. Read PDF (Read PDF)
  2. Configure (Edit Fields (Set))
  3. Is PDF (If)
  4. Is matched (If)
  5. Iterate over email attachments (Code)
  6. OpenAI matches PDF textual content (OpenAI)
  7. Merge (Merge)
  8. Upload file to folder (Google Drive)
  9. On email received (Gmail Trigger)
  10. Is text within token limit? (If)
  11. Has attachments? (If)

Credentials you need

  • Gmail OAuth2 – used by On email received
  • Google Drive OAuth2 – used by Upload file to folder
  • OpenAI API – used by OpenAI matches PDF textual content

Configure your own credentials after importing. Create each credential in n8n, then select it in the node.

How to import into n8n

  1. Download the JSON file with the button above.
  2. In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
  3. Open each node that shows a warning and select or create its credential.
  4. Read the notes on the canvas, test the workflow with sample data, then activate it.

Do you need somewhere to run it? Read our guide to self-hosted n8n.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us