Gmail Attachment Processor and Smart File Router - n8n Workflow

Automate Gmail attachment handling using this powerful n8n workflow. Filter by sender and file type, decompress ZIPs, upload to Google Drive, and notify via Slack using this versatile n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Operations managers dealing with automated reporting emails.
Developers needing to ingest files sent via email for processing.
Users seeking to implement robust email filtering and automated cloud synchronization.
Anyone looking for a comprehensive n8n workflow solution for Gmail management.

Overview

Manually downloading and sorting email attachments is tedious and prone to human error, especially when dealing with various file types or sources. This detailed n8n workflow template solves this by providing a hands-free, automated solution for file ingestion. The process ensures that only relevant emails are acted upon, attachments are split and filtered correctly, and complex files (like ZIPs) are handled appropriately before being uploaded to a designated location, such as Google Drive. This specific n8n workflow significantly enhances productivity by turning your inbox into a reliable, automated ingestion pipeline, making this n8n template invaluable for data management tasks.

How it Works

This automation starts with the crucial n8n trigger, the Gmail Trigger node, which constantly monitors your inbox for new emails containing attachments.


  1. Trigger and Initial Filter: The "Trigger on incoming email with attachment" n8n trigger fires upon finding a matching email (any email with an attachment). Immediately, the "Filter based on sender or receiver" n8n node checks if the email matches specific predefined criteria (sender or recipient addresses).

  2. Attachment Handling: If the email passes the sender/receiver filter, the "Split Out" n8n node separates the binary data (the attachments) from the email metadata. The "Loop attachments" n8n node then ensures that every single attachment is processed individually before the workflow proceeds.

  3. File Type Filtering: Each attachment then hits the "Filter based on file type" n8n node, which currently checks if the file is a ZIP or plain text. Files failing this check are discarded (or routed via the alwaysOutputData feature).

  4. Conditional Routing: The "Treat different file types different" n8n node (a Switch node) routes the attachments. If the file is a ZIP, it proceeds to the "Decompress zip" n8n node. Other files (like plain text) bypass decompression.

  5. Cloud Upload: Processed files (decompressed content or plain files) are uploaded using the "Upload file to Google Drive" n8n node to a specified folder. An alternative path is provided via the "Post file to webhook" n8n node for users who need to send the data to a custom API endpoint.

  6. Cleanup and Notification: Regardless of the upload path, the workflow circles back to the "Mark read and archive email" n8n node, cleaning up the inbox. Finally, the "Send a message" Slack n8n node provides a summary notification detailing how many files were processed and from which sender. This robust n8n workflow ensures reliable execution.

Installation Guide

To deploy this powerful n8n workflow template, follow these steps:


  1. Import: Copy the entire JSON code provided and paste it into your self-hosted or cloud n8n instance via the 'New' workflow screen > 'Import from JSON'.

  2. Credentials Setup: This n8n workflow requires three primary credentials:

Gmail Trigger: Configure credentials for the "Trigger on incoming email with attachment" n8n node. This needs read access to your mailbox.
Google Drive: Set up Google Drive credentials for the "Upload file to Google Drive" n8n node to ensure upload permissions.
* Slack: Configure Slack credentials for the "Send a message" n8n node.

  1. Customize Filters (Filter 1): In the "Filter based on sender or receiver" n8n node, modify the rightValue fields in the conditions to match the sender ([email protected]) or recipient addresses that you want this automation to target.

  2. Customize Filters (Filter 2): In the "Filter based on file type" n8n node, adjust the mimeType values if you need to process different file types (e.g., PDFs, CSVs, etc.). The Sticky Note provides a link to common MIME types.

  3. Activate: Once credentials and filters are configured, set the Gmail Trigger n8n node to 'Active' to start monitoring your inbox. This n8n template is now ready for production.

Node Details

This n8n workflow relies on several core n8n nodes for its functionality:

Gmail Trigger (Trigger on incoming email with attachment):
Function: Serves as the primary n8n trigger, initiating the process when an email with an attachment is detected.
Key Configuration: Filters are set to q: has:attachment -label:DRAFT. Downloads attachments automatically.

Filter (Filter based on sender or receiver):
Function: Filters the email data based on JavaScript expressions checking the sender or recipient address fields ($json.from.value[0].address).

Split Out / Split In Batches (Split Out / Loop attachments):
Function: These two n8n nodes work together to ensure that an email containing multiple attachments is processed item by item, providing robustness to the entire n8n workflow.

Filter (Filter based on file type):
Function: Checks the mimeType property of the binary data, currently configured to pass application/zip and text/plain files.

Compression (Decompress zip):
Function: An essential core n8n node that automatically extracts files contained within a ZIP archive, preparing them for the next processing step.

Google Drive (Upload file to Google Drive):
Function: The primary action n8n node responsible for saving the filtered and processed binary files to the specified Google Drive location, using the original attachment filename.

Gmail (Mark read and archive email):
Function: Performs housekeeping on the Gmail side, marking the email as read and removing the UNREAD and INBOX labels, effectively archiving it once the n8n workflow is complete.

Slack (Send a message):
* Function: Provides a final confirmation message detailing the execution status of the n8n workflow and the number of files processed.

Related n8n Workflows

Free

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

AI & Automation consultant with many years of experience from both devops and business management. A solid combination to really understand where technology can create real business value. My focus is to help businesses in Sweden work smarter and achieve more by applying technology in a useful and responsible way. Feel free to contact me at [email protected] or schedule a short call at https://smultronstudio.com

Featured*