Quick overview
This workflow checks Gmail every 15 minutes for invoice/receipt emails with attachments, uploads approved files to month-based folders in Google Drive, and records each file in a Google Sheets ledger, optionally labeling processed emails in Gmail and sending run alerts via Gmail or Slack.
How it works
- Triggers every 15 minutes when Gmail finds emails matching the search query and downloads their attachments.
- Reads existing rows from a Google Sheets ledger to skip attachments that were already logged.
- Filters attachments by allowed file types, generates a vendor-based filename and target month, and skips duplicates based on a SHA-256 fingerprint.
- Checks the target Google Drive parent folder for month subfolders and creates any missing month folders.
- Uploads each attachment to the correct month folder in Google Drive.
- Appends or updates a row in Google Sheets with metadata, Drive and Gmail links, and a status of “to review” (or “upload failed” when an upload fails).
- Adds a Gmail label to emails whose attachments were successfully filed and sends a run summary alert via Gmail or Slack when enabled or when issues occur.
Setup
- Connect credentials for Gmail, Google Drive, and Google Sheets, and add a Slack credential if you want Slack notifications.
- Create a Google Sheet with an “Invoices” tab and headers matching the workflow’s logged fields (for example: attachment_key, received, vendor, from, subject, file_name, folder, size, sha256, drive_link, email_link, amount, status, upload_error, logged_at).
- Create (or choose) a Google Drive parent folder for storing month subfolders, then set its folder ID along with your sheet URL/tab, allowed extensions, and notification settings in the “Invoice filing config” values.
- If you want emails labeled after filing, create the Gmail label (for example “Invoices/Filed”) and set the same name in the configuration.
- To receive crash alerts, set this workflow as the workflow-level error handler in n8n (Workflow settings → Error workflow).
Customization
- Edit the Gmail search, allow image attachments, change the month-folder format, or add vendor aliases in the config node.
Additional info
Only mail that arrives after you publish is processed (no backfill). Amounts are left blank for you to fill in.