This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"name": "Gmail Attachment Sender Folder - Final Working",
"nodes": [
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"simple": false,
"filters": {},
"options": {
"downloadAttachments": true
}
},
"type": "n8n-nodes-base.gmailTrigger",
"typeVersion": 1.3,
"position": [
-96,
-112
],
"id": "b6ee9ec3-a7cb-467f-8146-1dd13ba4b45d",
"name": "Gmail Trigger",
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "a7bd38aa-9145-4bd2-82c5-d4da191d7d1d",
"leftValue": "={{ $('Gmail Trigger').item.binary }}",
"rightValue": "",
"operator": {
"type": "object",
"operation": "exists",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.filter",
"typeVersion": 2.2,
"position": [
112,
-112
],
"id": "fbc77f51-1ffa-4a1b-a412-f69bcf5ee062",
"name": "Filter"
},
{
"parameters": {
"operation": "get",
"messageId": "={{ $json.id }}",
"simple": false,
"options": {
"downloadAttachments": true
}
},
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [
320,
-112
],
"id": "27f0f0b5-7b03-4fcb-936c-988b572a8e52",
"name": "Get a message",
"credentials": {
"gmailOAuth2": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "msg_id_assignment",
"name": "message_id",
"value": "={{ $json.id }}",
"type": "string"
},
{
"id": "parent_folder_assignment",
"name": "parent_folder_id",
"value": "1U1V3Dp4V_d07nltPhZ9PNd_DvJ8Zuu3E",
"type": "string"
},
{
"id": "sender_raw_assignment",
"name": "sender_raw",
"value": "={{ $json.payload.headers.find(h => h.name === 'From')?.value || '' }}",
"type": "string"
},
{
"id": "sender_email_assignment",
"name": "sender_email",
"value": "={{ $json.sender_raw.match(/<(.+?)>/)?.[1] || $json.sender_raw }}",
"type": "string"
},
{
"id": "sender_folder_assignment",
"name": "sender_folder",
"value": "={{ ($json.sender_email || 'unknown').toLowerCase().replace(/[/\\\\#%&{}<>*? $!'\":@+`|=]/g, '_') }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
500,
-112
],
"id": "prepare_sender",
"name": "Prepare sender"
},
{
"parameters": {
"url": "=https://www.googleapis.com/drive/v3/files",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "googleDriveOAuth2Api",
"sendQuery": true,
"queryParameters": {
"parameters": [
{
"name": "q",
"value": "=name='{{ $json.sender_folder }}' and mimeType='application/vnd.google-apps.folder' and '{{ $json.parent_folder_id }}' in parents and trashed=false"
},
{
"name": "fields",
"value": "files(id, name)"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
700,
-112
],
"id": "search_sender_folder",
"name": "Search sender folder",
"credentials": {
"googleDriveOAuth2Api": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict",
"version": 2
},
"conditions": [
{
"id": "folder_check_condition",
"leftValue": "={{ $json.files && $json.files.length > 0 }}",
"rightValue": "",
"operator": {
"type": "boolean",
"operation": "true",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
900,
-112
],
"id": "if_folder_exists",
"name": "Folder exists?"
},
{
"parameters": {
"resource": "folder",
"operation": "create",
"name": "={{ $('Prepare sender').item.json.sender_folder }}",
"options": {
"folderId": {
"__rl": true,
"value": "={{ $('Prepare sender').item.json.parent_folder_id }}",
"mode": "id"
}
}
},
"type": "n8n-nodes-base.googleDrive",
"typeVersion": 3,
"position": [
1100,
0
],
"id": "create_sender_folder",
"name": "Create sender folder",
"credentials": {
"googleDriveOAuth2Api": {
"name": "<your credential>"
}
}
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "folder_id_found",
"name": "folder_id",
"value": "={{ $json.files[0].id }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1100,
-220
],
"id": "use_found_folder",
"name": "Use found folder"
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "folder_id_created",
"name": "folder_id",
"value": "={{ $json.id }}",
"type": "string"
}
]
},
"options": {}
},
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [
1300,
0
],
"id": "use_created_folder",
"name": "Use created folder"
},
{
"parameters": {
"mode": "combine",
"combinationMode": "mergeByPosition",
"options": {}
},
"type": "n8n-nodes-base.merge",
"typeVersion": 2.1,
"position": [
1500,
-112
],
"id": "merge_folders",
"name": "Merge folders"
},
{
"parameters": {
"jsCode": "// Get folder ID from current item\nconst folderId = $input.item.json.folder_id;\n\n// Get binary data from Get a message node\nconst binaryData = $('Get a message').item.binary;\n\n// Create output array with one item per attachment\nconst outputItems = [];\n\nfor (const key in binaryData) {\n outputItems.push({\n json: {\n folder_id: folderId,\n attachment_name: key\n },\n binary: {\n data: binaryData[key]\n }\n });\n}\n\nreturn outputItems;"
},
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1700,
-112
],
"id": "split_with_binary",
"name": "Split with binary"
},
{
"parameters": {
"operation": "upload",
"folderId": {
"__rl": true,
"value": "={{ $json.folder_id }}",
"mode": "id"
},
"name": "={{ $json.attachment_name }}",
"binaryData": true,
"binaryPropertyName": "data",
"options": {}
},
"type": "n8n-nodes-base.googleDrive",
"typeVersion": 3,
"position": [
1900,
-112
],
"id": "upload_file",
"name": "Upload file",
"credentials": {
"googleDriveOAuth2Api": {
"name": "<your credential>"
}
}
}
],
"connections": {
"Gmail Trigger": {
"main": [
[
{
"node": "Filter",
"type": "main",
"index": 0
}
]
]
},
"Filter": {
"main": [
[
{
"node": "Get a message",
"type": "main",
"index": 0
}
]
]
},
"Get a message": {
"main": [
[
{
"node": "Prepare sender",
"type": "main",
"index": 0
}
]
]
},
"Prepare sender": {
"main": [
[
{
"node": "Search sender folder",
"type": "main",
"index": 0
}
]
]
},
"Search sender folder": {
"main": [
[
{
"node": "Folder exists?",
"type": "main",
"index": 0
}
]
]
},
"Folder exists?": {
"main": [
[
{
"node": "Use found folder",
"type": "main",
"index": 0
}
],
[
{
"node": "Create sender folder",
"type": "main",
"index": 0
}
]
]
},
"Create sender folder": {
"main": [
[
{
"node": "Use created folder",
"type": "main",
"index": 0
}
]
]
},
"Use found folder": {
"main": [
[
{
"node": "Merge folders",
"type": "main",
"index": 0
}
]
]
},
"Use created folder": {
"main": [
[
{
"node": "Merge folders",
"type": "main",
"index": 1
}
]
]
},
"Merge folders": {
"main": [
[
{
"node": "Split with binary",
"type": "main",
"index": 0
}
]
]
},
"Split with binary": {
"main": [
[
{
"node": "Upload file",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "4d4eff92-ce8b-4fed-8c00-36844be2edde",
"meta": {
"templateCredsSetupCompleted": true
},
"id": "DIFUbxCTf4T0kflc",
"tags": []
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
gmailOAuth2googleDriveOAuth2Api
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
How this works
Effortlessly organise incoming Gmail attachments by automatically routing them to dedicated folders in Google Drive based on the sender's email address, saving hours of manual sorting and ensuring important files are always accessible where you need them. This workflow suits busy professionals handling high volumes of emails with attachments, such as project managers or sales teams, who rely on Gmail and Google Drive for daily operations. The key step involves searching for or creating a personalised folder per sender using Google Drive integration, triggered seamlessly by new emails arriving in your inbox.
Use this workflow when you receive frequent attachments from recurring contacts and want to maintain a tidy, searchable Drive structure without constant intervention. Avoid it for low-volume inboxes or when attachments require complex processing beyond simple storage, like OCR or metadata extraction. Common variations include adding notifications via Slack for new folders or filtering by email subject to route attachments to project-specific directories.
About this workflow
Gmail Attachment Sender Folder - Final Working. Uses gmailTrigger, gmail, httpRequest, googleDrive. Event-driven trigger; 12 nodes.
Source: https://github.com/zxyphoon/projects/blob/9aeec33b0f9ca4d58dc1c28c8469b78d9b144b1b/n8n/idk.json — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Attachments Gmail to drive and google sheets. Uses stickyNote, gmailTrigger, httpRequest, googleDrive. Event-driven trigger; 17 nodes.
Automatically process labeled emails with attachments into organized Google Drive folders Teams or Individuals needing to: Automatically sort invoices, receipts, and files. Organize client documents b
AICARE Email Blast System. Uses googleDrive, httpRequest, googleSheets, gmail. Event-driven trigger; 39 nodes.
Client Form → Draft → Approve → Sign → Deliver, fully automated
This template is built to be customized for your specific needs. This template has the core logic and n8n node specific references sorted to work with dynamic file names throughout the workflow. Store