Work · Automation

Auto-file email attachments to Google Drive

An n8n workflow: mail arrives, the attachment is read, classified, filed into the right Google Drive folder and written to a ledger row. No one touches it. This is the kind of task where today's AI actually pays for itself — and most attempts at it still fall over.


A Gmail message lands, the attachment is converted to text, a cheap model classifies it, an expensive one extracts the fields, the document is filed to Accounting/2025/11_November/Expense/ in Google Drive and a row appears in the Sheets ledger. Workflow JSON, setup guide and the node-by-node breakdown are in the repo.

1 loginGoogle OAuth
Freerunning cost
120 minfrom scratch
10 minif n8n is running

One Google OAuth connection covers Gmail, Drive and Sheets; the models are Groq or Gemini Flash, both free tier. The two hours are the first-time cost — instance, Google connection, labels. With n8n already running other routines, adding this one is importing the workflow and preparing the spreadsheet: ten minutes.

Gmail inbox showing the n8n attachment workflow's labels on each email: messages tagged gdr and n8n with PDF invoice and receipt attachments filed to Google Drive, and one tagged only inProgress.
gdr + n8n means filed to Drive and finished; a message still carrying only inProgress never completed. Some senders and subjects blurred.

What this automation takes off your week

What n8n is, and why the connectors swap

n8n is a workflow tool you draw rather than write. Each step is a node on a canvas — a trigger, a service call, a snippet of code, a model — and arrows carry items between them. The node holds the credentials and API knowledge for its service, so after a run you click any node and see what went in and what came out. It runs on n8n’s cloud or self-hosted on your own machine, where it costs nothing and the documents never leave your infrastructure. Because the logic never names a vendor, every layer is replaceable:

LayerDefaultSwap for
MailGmail triggerOutlook, IMAP, a shared mailbox, a webhook
FilesGoogle DriveDropbox, SharePoint, S3, a local folder
LedgerGoogle SheetsAirtable, Notion, Postgres, Supabase
ModelsGroq · Gemini Flashanything with structured output
NotifyTelegramSlack, email, nothing at all

The two pieces that are not connectors are worth keeping: any-file2json-converter, which forces PDFs, DOCX and photos into one text shape, and the classify-then-route split that keeps the expensive model away from newsletters.

Other documents to point it at

Change the classifier prompt and the extraction schema and the same skeleton files something else:

Neighbouring shapes in the same repo: Telegram invoice OCR for paper you photograph, smart-table-fill for loose text into any table, LLM bulk responses for one prompt down hundreds of rows.

Why most email-attachment automations fail

They work on the invoice you picked and break on the next twelve. Four decisions carry this one: one login instead of five, a cheap model guarding the expensive one, one row per invoice rather than per file, and failures left visible as leftover inProgress labels. The AI part is two model calls; the rest is those four.

The n8n workflow canvas for auto-filing email attachments, showing three regions — attachment processor, AI subject classifier, and invoices and receipts — wired through Gmail, Gemini, Groq, Google Sheets, Google Drive and Telegram nodes.
37 nodes: attachment processing, classification and routing, extraction and filing. Breakdown in mainflow.md.
Workflow + setup guide ↗ All n8n micro-services ↗