n8n

How to Automate Gmail PDF Filing to Google Drive?

Stop dragging invoices and receipts from your inbox. This setup watches new Gmail messages, checks their PDF attachments, and files the right ones into a Google Drive folder. It is great for invoices, receipts, contracts, or payslips where you only want specific files saved.

It starts when a new email arrives in Gmail. The flow splits all attachments, filters to PDFs, and reads the text. A size check makes sure the text fits the model limit. OpenAI then answers with true or false to a simple question based on your Match on term. Files marked true are sent to your chosen Google Drive folder. Items that are not PDFs, have no attachments, or are too large are safely ignored.

You only need Gmail, Google Drive, and OpenAI accounts. In the Configure step, set Match on, paste your Drive folder link, and choose token settings. Expect big time savings as the filing work moves from manual sorting to a reliable rule. Use it for accounts payable, payroll documents, or vendor contracts. Send yourself a test email with a sample PDF to confirm the path before going live.

What are the key features?

  • Gmail trigger watches incoming emails and downloads attachments automatically.
  • Code step splits multiple attachments so each file is checked on its own.
  • PDF filter ensures only PDF files move forward for processing.
  • PDF reader extracts text content for analysis.
  • Token limit check prevents large documents from exceeding model limits.
  • OpenAI classifies the PDF using your Match on term and returns true or false.
  • Merge keeps AI output aligned with the original file for accurate decisions.
  • Google Drive upload saves only matched PDFs to the folder you choose.
  • Branches handle no attachments, non PDF files, and large PDFs safely.

What are the benefits?

  • Reduce inbox filing from 60 minutes to 5 minutes per day
  • Automate up to 90 percent of attachment sorting
  • Cut misfiled documents by up to 80 percent with AI checks
  • Handle 10 times more email volume without extra staff
  • Connect Gmail and Google Drive into one clean flow

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Gmail, Google Drive and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. Open the Gmail Trigger node, choose your inbox or label if needed, and confirm Download Attachments is enabled. In the Credentials field, click Create new credential and follow the on screen steps to connect your Google account for Gmail.
  4. Open the OpenAI node. In Credentials, click Create new credential. On the OpenAI website, create an API key from your account page, then paste it into n8n. Name the credential clearly, for example OpenAI Prod.
  5. Open the Google Drive node. In Credentials, click Create new credential and follow the on screen Google sign in. Allow file access so n8n can upload PDFs.
  6. Open the Configure node. Set Match on to the document type you want, for example invoice or payslip. Paste the Google Drive folder link into the provided field. The workflow extracts the folder ID automatically.
  7. Check token settings in Configure. Set maxTokenSize to match your OpenAI model and replyTokenSize to the expected short answer. The default values are safe for true or false replies.
  8. Send a test email to your Gmail with two attachments: one matching PDF and one non matching PDF or a non PDF file. Confirm the matching file uploads to your Drive folder and the others do not.
  9. Review the Execution view in n8n. If a PDF is ignored due to size, increase maxTokenSize or reduce replyTokenSize. Very large PDFs may need to be split before sending to the inbox.
  10. If uploads fail, verify the Drive folder link is correct and that your Google Drive credential has access to that folder. Try selecting a different folder to test permissions.
  11. If classification is off, adjust Match on to be more specific, for example supplier invoice instead of invoice, then resend a sample and check the result.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

Gmail

Sign up

No cost: Personal Gmail (Gmail API has no usage-based pricing; quotas apply)

Google Drive

Sign up

Drive API: $0 (no additional cost; quota-limited)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Credits:
Workflow by David Sha.

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.