Automatic Email Attachment Organizer to Google Drive - n8n Workflow

Automate Gmail attachment saving to Google Drive using a robust n8n workflow. It creates sender-specific folders, ensures perfect organization, and avoids duplicates.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

System Administrators & Integrators: Seeking reliable n8n templates for email processing.
Virtual Assistants & Solopreneurs: Managing high volumes of incoming documents and files.
Automation Specialists: Looking for a sophisticated n8n workflow example utilizing conditional logic and recursion.
Anyone needing automatic, organized archival of email attachments based on the sender.

Overview

Managing email attachments manually can be time-consuming and lead to disorganized cloud storage. This robust n8n workflow solves this by providing a completely automated solution for filtering, extracting, and organizing files from Gmail directly into Google Drive.

This specific n8n automation is designed for meticulous organization. When a new email arrives, the n8n node determines the sender's email address and uses it as the folder name. Crucially, before creating a new folder, the n8n workflow uses a Google Drive node to check if a folder for that sender already exists. If it exists, the files are placed inside; if not, a new folder is created on the fly. This sophisticated conditional logic, combined with a recursive Execute Workflow n8n node structure for efficient batch processing, ensures your Google Drive stays clean, structured, and free of duplicate folders. This powerful n8n node setup provides exceptional reliability for file management.

How it Works

This comprehensive n8n workflow uses a nested structure for efficient processing:


  1. Initiation: The primary path starts with the Gmail Trigger n8n trigger, which constantly monitors your inbox for new messages. For manual testing, the Manual Trigger initiates the flow, fetching emails using the Get emails n8n node.

  2. Batch Processing: The workflow uses a Loop Over Items (Split in Batches) n8n node combined with an Execute Workflow n8n node, executing itself recursively for each email. This isolates processing and improves reliability.

  3. Data Extraction: Within the sub-workflow, the Get email n8n node retrieves the full email body and downloads all associated attachments (binary data).

  4. Conditional Logic (Attachments): An If n8n node (Contain attachments?) checks if any binary data exists. If not, the processing stops for that item.

  5. Folder Verification: The Search folders Google Drive n8n node searches the designated parent folder for a sub-folder matching the sender's email address.

  6. Conditional Logic (Existence): The Exist? n8n node determines the path: if the folder exists, the flow proceeds to the Folder ID n8n node to capture the existing ID. If it does not exist, the Create folder n8n node creates a new folder using the sender's email as the name.

  7. Attachment Preparation: The Get attachments custom Code n8n node processes the complex binary data structure from Gmail, mapping each attachment into a usable format with its filename, preparing it for upload.

  8. Final Action: The Upload attachment Google Drive n8n node executes, placing the file into the dynamically determined sender-specific folder. This complete n8n workflow provides fully automated organization.

Installation Guide

To install this n8n workflow and start using these n8n templates, follow these steps:


  1. Import: Copy the provided n8n workflow JSON and paste it directly into your n8n canvas using the 'Import from JSON' function.

  2. Credentials Setup:

Gmail Credentials: You need valid OAuth2 credentials for the Gmail n8n node and the Gmail Trigger n8n trigger. Ensure the scope allows reading emails and downloading attachments.
Google Drive Credentials: Provide OAuth2 credentials for the Google Drive n8n node. This connection must have permissions to search for folders, create folders, and upload files.

  1. Configuration:

Parent Folder: In the Search folders and Create folder n8n nodes, ensure the folderId is set to your desired parent folder (e.g., 'Email Attachments') where the sender-specific folders will reside.
Trigger Mode: Activate the Gmail Trigger n8n trigger for continuous, automatic execution, or use the manual trigger for initial testing.

  1. Activate: Set the workflow to 'Active' to enable the n8n trigger.

Node Details

Gmail Trigger: This essential n8n trigger polls your Gmail inbox for new emails. It is configured to run every minute (everyMinute).
Get emails (Gmail n8n node): Used in the manual path to fetch emails. Key configuration: operation: getAll with downloadAttachments: true.
Get email (Gmail n8n node): Fetches the full email details based on the message ID from the preceding item. Also ensures downloadAttachments: true.
Contain attachments? (If n8n node): A core logic n8n node that checks if the $binary object is not empty, filtering out emails without files.
Search folders (Google Drive n8n node): Searches the parent directory using the sender's email address (={{ $('Get email').item.json.from.value[0].address }}) as the search query. It limits results to 1 (limit: 1).
Exist? (If n8n node): Checks the output of the Search folders n8n node. If the output JSON is not empty, the folder exists.
Create folder (Google Drive n8n node): Creates a new folder. The folder name is dynamically set using the sender's email address.
Get attachments (Code n8n node): This custom n8n node iterates through the raw binary keys provided by the Gmail n8n node and restructuring the data so that each attachment is an individual item ready for the Upload attachment n8n node.


  • Upload attachment (Google Drive n8n node): Handles the file upload. The folderId is dynamically pulled from the result of the Folder ID or Create folder n8n nodes, ensuring files land in the correct sender folder.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all
Created by

Full-stack Web Developer based in Italy specialising in Marketing & AI-powered automations. For business enquiries, send me an email at [email protected] or add me on Linkedin.com/in/davideboizza

Featured*