n8n

How to Automate Gmail to Drive Document Filing?

Stop dragging email PDFs into folders by hand. This setup watches a Gmail inbox, reads each PDF, and files only the documents you care about into a Google Drive folder. It is great for invoices, receipts, payslips, and contracts.

Here is how it works. A Gmail trigger grabs new emails and downloads attachments. A code step splits multiple attachments so each file is checked on its own. Non PDF files are skipped. The PDF text is extracted and checked against a safe token limit. OpenAI then looks at the text and answers true or false based on a match term you set, like invoice or payslip. A merge and filter step pairs the AI answer with the file and sends matching PDFs to your chosen Google Drive folder. Large files and non matches are ignored.

You only need Gmail, Google Drive, and an OpenAI API key. In one place, set your match word, paste your Drive folder link, and choose token limits. Send a test email to confirm one file is filed and one is skipped. Teams can cut document triage by up to 90 percent and keep files organized without manual sorting. Finance, HR, and operations can all benefit.

What are the key features?

  • Gmail trigger polls every minute and downloads attachments automatically.
  • Code step splits multiple attachments so each file is reviewed on its own.
  • PDF filter only processes .pdf files and skips others cleanly.
  • Read PDF extracts the text content for analysis.
  • Token guard checks text size to avoid model limits and ignores oversized files.
  • OpenAI classifies the PDF content against your match word and returns true or false.
  • Merge pairs the AI result with the original file for accurate routing.
  • Google Drive upload sends matched PDFs to a folder using the ID from a pasted link.
  • Configure node stores the match term, folder link, and token sizes in one place.

What are the benefits?

  • Reduce manual sorting from 30 minutes a day to under 2 minutes
  • Automate up to 90 percent of document filing from email
  • Eliminate 100 percent of manual downloads and uploads
  • Lower filing mistakes by using a clear true or false check
  • Handle hundreds of incoming emails per day without extra staff

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 On email received node and in the Credential to connect with dropdown click Create new credential, then follow the on screen steps to connect your Gmail account. Confirm Download Attachments is on and the polling is Every minute.
  4. Open the Upload file to folder node and create a new Google Drive credential. Follow the on screen steps to authorize Drive. Use a clear credential name like Google Drive Finance or Google Drive HR.
  5. Open the OpenAI matches PDF textual content node. Create a new OpenAI credential and paste your API key from the OpenAI dashboard API keys page. Save the credential with a clear name.
  6. Open the Configure node. Set Match on to the word you want to detect such as invoice, receipt, contract, or payslip. Paste the Google Drive folder link you want to use. Set maxTokenSize and replyTokenSize based on your model limits.
  7. Check the If nodes. Is PDF should compare the file extension to pdf. Is text within token limit should be true before the OpenAI node runs. Leave temperature low for stable answers.
  8. Send a test email to the connected Gmail inbox with two PDFs, one that matches and one that does not. Open the n8n execution to watch each step. Confirm the matched file appears in the Drive folder and the non match is skipped.
  9. Test a large PDF to verify the Ignore large PDFs path catches it. If it slips through, lower maxTokenSize or increase replyTokenSize to stay safe.
  10. If nothing matches, review the OpenAI response text and the Is matched condition. Make sure the prompt requests true or false in lowercase and that the condition checks for true correctly.
  11. If the upload fails, confirm the Drive folder ID is correct by using the last part of your folder link, and ensure your Google Drive credential has access to that folder.

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 written 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.