Automatically File Email Attachments into Google Drive with n8n and AI
This n8n workflow takes every attachment from new Gmail messages, reads PDF text, and asks an AI model whether it is an invoice, receipt, contract, identity document or something else. It renames the file in a consistent date, type, party and reference format, saves it to the matching Google Drive folder, and logs it in Google Sheets. Unsure results are marked CHECK and saved to a To sort folder.
- Difficulty
- Beginner
- Setup time
- About 40 minutes
- Nodes
- 9
- Checked against
- n8n 2.41
- Gmail
- OpenAI or Anthropic
- Google Drive
- Google Sheets
Last reviewed October 2026
What this workflow does
Attachments pile up in inboxes. Invoices sit next to signed contracts, receipts and copies of a new starter's driver licence, all with file names like scan_0042.pdf. When the accountant asks for last quarter's receipts or someone needs a contract, it means searching email and downloading files one by one.
This template is for small offices, practices and bookkeepers who want documents to land in a tidy Drive structure without anyone dragging and dropping. The AI only decides the type and a sensible name; the folders, naming rules and access permissions stay under your control, and low-confidence calls are left for a person to sort.
Who it's for
- →Small business owners who keep receipts and invoices in Google Drive
- →Office managers handling a shared admin or accounts inbox
- →Bookkeepers who collect client documents by email
- →Professional services firms that want contracts filed consistently
How it works, step by step
- 1
Watch Gmail for attachments
The Gmail trigger polls for new messages with attachments and downloads them. Narrow the search query to a label or address so personal email is not processed.
- 2
Make one item per attachment
A Code node splits each email into one item per file and drops small inline images such as logos in email signatures. It keeps the sender, subject, date and a short snippet of the email body.
- 3
Check whether the file is a PDF
An If node sends PDFs to text extraction. Images, Word files and spreadsheets skip extraction and are classified from their file name and the email details.
- 4
Read the PDF text
The Extract from File node pulls the text from each PDF. If a PDF is encrypted or damaged, the node continues without text rather than stopping the run.
- 5
Classify the document with AI
The Information Extractor node asks your chat model for the document type, the other party, the document date, any reference number, a short title and a confidence rating, using clear definitions for each type.
- 6
Build the file name and folder
A Code node maps the type to a Drive folder ID and builds a name like 2026-09-14 - Invoice - Supplier Name - INV-1042.pdf. Low-confidence results get a CHECK prefix and go to the To sort folder.
- 7
Save to Google Drive
The Google Drive node uploads the original file, unchanged, to the chosen folder with the new name. The original email and attachment stay in Gmail.
- 8
Log the filing
Google Sheets records when the file was filed, who sent it, the subject, the original and new names, the type, the confidence and a link to the file in Drive.
What you need
Gmail or Google Workspace account
The inbox the attachments arrive in, ideally with a label or filter for business documents.
Google Drive
Folders for invoices, receipts, contracts, ID documents and a To sort folder, shared with the right people.
OpenAI or Anthropic API key
Any current chat model with structured output. Classification is a light task, so a smaller model is fine.
Google Sheets
A spreadsheet with a Filing log tab for the audit trail.
n8n instance
n8n Cloud or self-hosted. Self-hosting in an Australian region keeps file handling onshore.
Set it up in n8n
- 1
Import the workflow JSON into n8n and read the Setup Notes sticky note.
- 2
Connect Gmail and change the trigger's search query to the label or address you want to process, then set a polling interval.
- 3
Create the Drive folders and paste their IDs into the FOLDERS list at the top of the Build File Name and Folder node.
- 4
Restrict sharing on the ID documents folder to the people who need it, and keep it separate from folders shared with your accountant.
- 5
Connect Google Drive and Google Sheets, create a Filing log tab with the listed headers, and paste the sheet ID.
- 6
Add your OpenAI credential to the Chat Model node, or replace it with an Anthropic Chat Model connected to Classify Document.
- 7
Forward a handful of real attachments to the inbox, run the workflow manually and check the names, folders and log before activating.
Ways to customise it
- +Add more document types, such as payslips, BAS statements or insurance certificates, by extending the schema, the system prompt and the FOLDERS list.
- +Create year and month subfolders automatically with Google Drive search and create folder nodes before uploading.
- +Send invoices on to the invoice-to-Xero workflow after filing, so bills are entered and the PDF is already in Drive.
- +Apply a Gmail label such as Filed to each processed email so your team can see what has been handled.
- +Post a Slack or email alert when an ID document is filed, so someone can confirm it was expected.
For Australian businesses
Identity documents such as driver licences, passports and Medicare cards are personal information that needs careful handling under the Privacy Act 1988. APP 11 expects reasonable steps to protect it, so give the ID folder restricted sharing and delete copies you no longer need. The workflow only sends PDF text, file names and a short email snippet to the AI model; images, including photographed IDs, are classified from their name alone. Sending document text to an offshore AI API is a cross-border disclosure under APP 8, so review the provider's data terms or self-host n8n in an Australian region. For tax records, the ATO generally expects you to keep them for five years, and a tidy Drive structure makes that easier.
Tools in this workflow
n8n
Free plan + paidAutomation
A workflow automation platform that combines a visual node editor with code when you need it. It connects hundreds of apps and APIs and includes AI agent nodes that can call language models, tools and memory. Teams can self-host the free Community Edition on their own servers or use n8n's hosted cloud.
Best for: Australian organisations that need automation data to stay onshore
n8n review →ChatGPT (OpenAI)
Free plan + paidGeneral Assistant
OpenAI's general-purpose AI assistant. It handles writing, coding, file and image analysis, data analysis and web research through a chat interface, with an API for building it into your own systems.
Best for: Small and mid-sized teams wanting one general assistant for everyday writing and analysis
ChatGPT review →Claude (Anthropic)
Free plan + paidGeneral Assistant
Anthropic's AI assistant, known for careful reasoning, long-document analysis, writing and coding. It can work through large documents and codebases in a single conversation, paid plans include the Claude Code agentic coding tool, and it is available through an API and major cloud platforms.
Best for: Legal, policy and consulting teams reviewing long documents
Claude review →Zapier
Free plan + paidAutomation
A no-code automation platform that links a large catalogue of web apps through workflows called Zaps. Beyond triggers and actions it now offers AI agents, chatbots, Tables for storing data, Interfaces for simple forms and pages, and an MCP server that lets AI assistants run Zapier actions.
Best for: Small businesses automating admin without developers
Zapier review →Make
Free plan + paidAutomation
A visual automation platform, formerly Integromat, where workflows called scenarios are built on a drag-and-drop canvas. It handles branching, iteration and error routes across a large library of apps, and adds AI agents and AI modules that can reason over data within a scenario. Make is owned by process mining company Celonis.
Best for: Operations teams building complex multi-step workflows without code
Make review →
Frequently asked questions
Does the AI see photos of ID documents?
No. Only PDFs go through text extraction. Images are classified using the file name, email subject and a short snippet of the email body, so the picture itself is never sent to the model. Image files that cannot be identified confidently are marked CHECK for a person.
What happens if the AI gets the type wrong?
The original file is unchanged and still in Gmail, so nothing is lost. Results the model rates as low confidence go to the To sort folder with a CHECK prefix. For the rest, the Filing log shows the type chosen, so a quick weekly check catches mistakes.
Can it file into a shared drive instead of My Drive?
Yes. In the Save to Google Drive node, pick the shared drive in the Drive field and use folder IDs from that shared drive in the FOLDERS list. The connected Google account needs permission to add files there.
Will it process every email in my inbox?
Only new emails that match the trigger's search query. The default query takes any email with an attachment, so narrow it to a label, a forwarding address such as documents@ or specific senders before activating the workflow.
More finance & admin templates
Other n8n templates
- Speed to Lead: AI Lead Qualification from Website Form to HubSpot
- AI Company Research Agent: Lead Research Briefs Saved to HubSpot
- AI Email Triage for Gmail: Labels, Draft Replies and a Daily Digest
- RAG Website Support Chatbot from Your Google Drive Docs with Human Handoff
- Daily Business KPI Digest from Stripe, Shopify and GA4
- AI Google Review Reply Drafts with Slack Approval
Want this running in your business?
AI Lab Australia sets up n8n workflows end to end: hosting in Australia, connecting your systems, testing with real data and handing over documentation.
