Automated Email Attachment Organizer using Gmail, Google Sheets & Drive - n8n Workflow

Use this efficient n8n workflow to automatically download Gmail attachments, lookup sender companies in Google Sheets, and organize files into year/month folders in Google Drive.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Accounting teams handling incoming invoices or receipts.
Businesses needing automated vendor file organization based on a predefined whitelist.
Users looking for advanced examples of n8n templates integrating multiple services.
Anyone needing a reliable n8n workflow to automatically move and categorize data between Gmail, Google Sheets, and Google Drive.

Overview

Managing incoming attachments, especially high-volume items like invoices or receipts, can be tedious and prone to manual error. This powerful n8n workflow solves the problem of manual filing by providing an automated, smart categorization system. It leverages a Google Sheets whitelist (defined by the Lookup in Sheets n8n node) to map sender emails to specific company names.

When a new email matches the criteria set in the n8n trigger, the n8n workflow executes a series of intelligent file management actions: dynamically searching for the corresponding Company folder, and then creating a nested YYYY/MM folder structure within that company's directory if it doesn't exist. This complex organizational logic is handled seamlessly by the subsequent n8n node configuration, ensuring every attachment is downloaded, split, and stored correctly in Google Drive, prefixed with a timestamp for unique identification. This is a crucial and robust n8n workflow for improving document management and operational efficiency.

How it Works

The n8n automation starts with the Gmail Trigger n8n node, which constantly polls for new emails matching a predefined Gmail filter (e.g., having a specific label, often applied to emails containing attachments or keywords like 'invoice').


  1. Sender Identification: Once triggered, the sender's email address is used by the Lookup in Sheets n8n node to fetch the corresponding company name from a Google Sheets whitelist.

  2. Company Folder Management: The n8n workflow then initiates a hierarchical folder check in Google Drive using the Search Company Folder1 n8n node. If the folder for that company doesn't exist, the Create Company Folder n8n node generates it under a specified parent folder.

  3. Date Folder Management: The YYYY/MM n8n node dynamically calculates the current year/month folder name based on the email date. The n8n node Search For Folder checks for this folder inside the company directory. If missing, Create Month Folder generates it.

  4. Attachment Download: After the target Google Drive location is secured, the Gmail n8n node downloads the attachments from the triggered email.

  5. Data Preparation: The attachments are processed by the Split Up Binary Data1 Function n8n node. This essential step transforms the single input item (containing all files) into multiple items, one for each attachment, preparing them for the batch upload loop.

  6. Final Upload: Finally, the Upload To Folder n8n node saves each individual file, prefixed with a timestamp, into the correct nested Google Drive folder ID determined earlier. This reliable n8n workflow ensures organized archiving.

Installation Guide


  1. Import the n8n Workflow: Copy the provided JSON code and import it into your n8n instance using the 'New' > 'Import from JSON' option.

  2. Gmail Credentials: Set up credentials for the Gmail Trigger n8n node and the Gmail n8n node. Ensure your account is authorized to read the necessary labels.

  3. Google Sheets Whitelist: As indicated in the sticky note, create or copy a Google Sheet containing email and company columns. Update the Lookup in Sheets n8n node with the correct Document ID and Sheet Name.

  4. Google Drive Credentials: Set up credentials for the Google Drive n8n node. Ensure this account has permissions to search, create, and upload files to the specified parent folder (configured in the Create Company Folder n8n node, currently set to 'Invoices').

  5. Filter Configuration: Ensure the Gmail Trigger n8n trigger is correctly configured to monitor the label you are using for filtered emails (e.g., Label_2).

  6. Activate: Save and activate the n8n workflow.

Node Details

Gmail Trigger (n8n trigger): Monitors Gmail via polling (every 15 minutes). It is filtered to process only emails associated with a specific label (Label_2). This n8n trigger initiates the entire automation.
Lookup in Sheets (Google Sheets n8n node): Queries a Google Sheets document based on the sender's email address to retrieve the associated company name, which is crucial for folder naming.
Search Company Folder1 / Create Company Folder (Google Drive n8n node): Manages the top-level company folder. It searches for the company folder using the name retrieved from Google Sheets and creates it if it does not exist, storing it under a predefined parent folder ID.
YYYY/MM (Set n8n node): A logic n8n node that uses an expression to dynamically format the date from the email into a YYYY/MM string for folder naming (e.g., 2024/07).
Gmail (Gmail n8n node): Performs the get operation on the triggered message ID. Key configuration includes enabling downloadAttachments: true, essential for passing file data down the n8n workflow.
Split Up Binary Data1 (Function n8n node): This custom code n8n node takes the attachments downloaded by the Gmail n8n node and splits them into separate items, ensuring that the subsequent Upload To Folder n8n node processes each attachment individually.


  • Upload To Folder (Google Drive n8n node): The final action. This n8n node uploads the individual binary attachment data (=data) to the dynamically determined folder ID (which could be the search result ID or the newly created folder ID), ensuring files are stored correctly with a unique timestamp prefix.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by
Ventsislav Minev
Ventsislav Minev

IT professional and n8n enthusiast

Featured*