To file invoice attachments automatically, select the right emails, download each PDF and save it to a known Drive folder. Keep a record of each processed attachment so the next run does not save another copy.
A Gmail filter can organise the incoming messages. A workflow builder can handle the file transfer. An agent-building tool lets you describe the workflow before reviewing the proposed steps.
Decide what belongs in the folder
Start with a short list of suppliers and a folder you control. Do not treat every PDF in your inbox as an invoice: contracts, brochures and booking confirmations also arrive as PDFs.
For this example, the rule is:
- Read messages carrying the label
Invoice intake. - Process PDF attachments only.
- Save each original PDF into
Invoices/YYYY-MM, using the month the email arrived. - Preserve the email and record the saved file’s link.
The folder month is an organisational choice. It does not determine the invoice’s accounting period.
For example, a fictional supplier email arriving on 4 November with two invoice attachments should create two files in Invoices/2026-11. Running the workflow again should create none.
Option 1: Use a Gmail filter to organise incoming invoices
In Gmail, open the search options and enter criteria for a known supplier and messages with attachments. Check the search results, create a filter and apply your Invoice intake label. Google’s filter instructions explain the available actions.
This is enough if your main problem is finding invoices later. Gmail filters organise messages; their listed actions do not include uploading attachments to Drive. For automatic file transfer, add another step outside the filter.
Use a sample of recent messages to check the rule before expanding the supplier list. A broad subject search such as “invoice” can include reminders with no invoice attached.
Option 2: Automate Gmail invoice filing with Pillow
Pillow is an AI assistant that helps you build repeatable automations from plain-English instructions. Its workflow builder lets you inspect the steps and refine the process before enabling it.
For invoice filing, give Pillow the supplier rules, Gmail label and destination Drive folder. The prompt below describes how to collect the PDFs, preserve the originals and track what has already been saved.
Connect the accounts or folders the workflow needs and review any missing actions or settings Pillow identifies. Copy this prompt into Pillow to start:
Create a workflow that archives my Gmail invoice PDFs in Google Drive.
Use messages labelled Invoice intake. Process PDF attachments only.Save the original PDFs under the Drive folder I choose, in YYYY-MMsubfolders based on the email's received date in my timezone.
Keep the original emails. Record the source message ID, attachment IDand saved Drive file ID. Avoid duplicate files on repeat runs, includinga retry after an upload succeeds but recording its result fails.If an attachment cannot be downloaded or uploaded, report it as failedand leave it available for retry. Do not mark it complete.
First, show me any missing connections or settings. Build a disabledworkflow and test it on two messages I select, including one with twoPDFs. Show me the saved files and the repeat-run result before enablinga recurring schedule.Copy the prompt above, then open Pillow to build your automation.
Option 3: Build the transfer in n8n
n8n publishes a Gmail attachment backup workflow that provides a starting point for copying attachments from a selected sender into Drive. Its Google Drive node supports file upload and folder creation.
Adapt the workflow around your filing rules:
- Connect the Gmail account and destination Drive account. Use a test folder first.
- Select eligible messages. If using a new-message trigger, remember that historical messages need a separate backfill run.
- Retrieve the actual attachment files, not just message headers. Process each PDF separately and keep its original message and attachment identifiers.
- Check a saved processing record keyed by message ID plus attachment ID. Skip records already completed.
- Find or create the destination month folder, then upload the original PDF. Use a collision-resistant filename when two attachments share a name.
- Save the resulting Drive file ID and mark the attachment complete only after the upload succeeds.
A filename search alone is not reliable duplicate detection. Two different invoices can both be called invoice.pdf.
There is also a retry gap to handle: the upload may succeed while writing the processing record fails. Give the uploaded file a recoverable source identifier and check for that file before retrying. Otherwise, a retry can create a duplicate even when ordinary repeat runs work.
This route suits you if you want to control the selection, naming and recovery rules directly. You still maintain the connections and the workflow.
Configure the Gmail search and Drive upload
First make the selection work in Gmail itself. For a fictional supplier, try from:billing@example.com has:attachment filename:pdf newer_than:30d. Replace the address, open several results and confirm that they contain the documents you want. filename:pdf narrows the candidates; it does not prove that every matching attachment is an invoice. Gmail’s search operators can be combined in one query.
Create the label and filter after checking those results. For an existing archive, apply the label to the historical messages you want included. Keep the first backfill to one month so you can compare the number of selected attachments with the number of saved files.
In n8n, use Gmail → Message → Get Many to inspect a bounded batch. Select the label and include both read and unread messages. An invoice should not disappear from the automation just because you opened it earlier. The node exposes label, search and read-status filters. Its simplified result contains message metadata, so you still need to retrieve the attachment contents for upload. Gmail node settings.
Check the output at the attachment step before connecting Google Drive. You should have a PDF file payload, a filename and the source identifiers. A subject line or an attachment’s name on its own is not the file. If an email has three PDFs, the upload stage needs to receive three attachment records.
For the Google Drive → File → Upload operation, map the binary input field to the actual file field produced by the preceding step. Select the parent Drive and folder explicitly. The field name depends on the attachment reader, so use the previous step’s output rather than typing a guessed name. Drive upload configuration.
Create one month folder and retain its folder ID for the rest of the batch. Repeatedly creating a folder with the same name can scatter a month’s invoices across several identical-looking folders. Once the first upload succeeds, open the saved file from the returned link and check its page count and filename.
Keep a useful processing register
A small register makes the workflow easier to inspect and recover:
| Column | Why it matters |
|---|---|
| Source key | Message ID plus attachment ID identifies one input |
| Original filename | Helps you recognise the source document |
| Received date | Explains the chosen archive month |
| Destination folder ID | Keeps uploads in the intended folder |
| Saved file ID | Links the input to the actual Drive file |
| Result and last error | Separates saved files from work that needs attention |
Write a pending record before upload and update it after success. If a run stops halfway through, inspect pending records before retrying. Keep the source key with the destination file, using a supported metadata field or a stable filename suffix, so you can find a successful upload whose final register update failed.
If two runs could overlap, run this archive one batch at a time or use a store that enforces a unique source key. A spreadsheet lookup followed by an append is not enough to prevent simultaneous runs from both saving the same attachment.
Before you leave it running
| Test | Expected result |
|---|---|
| One email with two PDFs | Two files, each linked to its source |
| The same email processed twice | No extra copies |
Two different attachments named invoice.pdf | Both preserved |
| A non-PDF attachment | Skipped without blocking the valid PDFs |
| Drive upload fails | Visible failure with a retry path |
| Upload succeeds but the processing record fails | Recovery finds the uploaded file |
Once those checks pass, expand the supplier list and the volume. Keep financial extraction separate until the file archive itself is reliable.
Questions about saving Gmail attachments to Drive
Can a Gmail filter save invoice attachments to Google Drive?
A filter can label or organise the message. The transfer needs a workflow, script or other tool that reads the attachment and uploads the file. Keep the Gmail filter as the selection step if it already identifies the right messages.
What about invoices delivered as download links?
They need a separate process. A supplier-portal link is not a PDF attachment, and it may require a login or expire. Put those messages in a separate queue instead of marking them archived when no document has been saved.
Will this import invoices that are already in my inbox?
Only if you include a backfill. A new-message trigger does not automatically process the old archive. Select a historical date range, inspect its files and record them with the same source keys used for future runs.