Overview
This lesson is part of the n8n AI Automation - Zero to Hero course, Section: 5. Hands-On Projects.
Watch the video above for the full tutorial, or read the written guide below.
What Is the Gmail-to-Google Drive Attachment Workflow in n8n?
The Gmail Trigger node anchors an n8n automation that saves email attachments directly to a Google Drive folder and fires a Discord team notification. The four-node chain runs: Gmail Trigger polling the inbox every minute, a Filter node discarding emails with no binary data, a Google Drive upload node, and a Discord webhook node. Emails with multiple attachments need a fifth node, Split Out, to fan each binary field into its own item before the upload.
How to Build the Gmail Attachment Auto-Save Workflow in n8n
The Gmail Trigger, Filter, Split Out, Google Drive, and Discord nodes chain together to route every email attachment into a designated Drive folder automatically. Configure the Gmail Trigger to download attachments, gate with a binary-exists Filter, fan multi-attachment emails through Split Out, use two dynamic expressions in the Google Drive node to resolve field names and filenames, and send a Discord webhook notification on each upload.
The Gmail Trigger node starts with the "On Message Received" event. Disable the "Simplify" toggle so the full email payload is available, then enable "Download Attachments" with the default prefix attachment_. That prefix is critical: n8n names every binary field attachment_0, attachment_1, and so on, and every downstream expression depends on that naming convention. Add a Filter node next with the condition set to expression $binary, type Object, condition Exists. This gate silently drops plain-text emails before they reach the upload node.
The Split Out node solves the multiple-attachment problem. A Gmail email with nine attachments arrives in n8n as one item carrying nine binary fields, not nine separate items. Set the Split Out field to $binary so it outputs nine individual items. In the Google Drive node (resource: File, operation: Upload), replace the hardcoded attachment_0 in "Input Data Field Name" with the expression {{$binary.keys().first()}}. This dynamically returns the correct binary key for whichever item is currently being processed. For "File Name," use {{$("Filter emails with attachments").item.json.subject}}_{{$binary.values().first().fileName}} to combine the email subject with each attachment's original filename stored in the binary metadata. Select the target parent drive and destination folder to complete the upload configuration.
The Discord node completes the chain using a webhook credential, not a bot token. Reference the email subject from the Filter node in the message body. Because nine attachments produce nine separate Discord messages, place an Aggregate or Code node upstream of Discord to collapse them into a single team notification.
Key Takeaways
- The Gmail Trigger requires "Download Attachments" enabled and the
attachment_prefix set; without it, no binary data flows to any downstream node. - The Filter node checks
$binaryObject Exists to catch any email carrying at least one attachment, regardless of the exact field name or total attachment count. - The Split Out node set to
$binaryconverts one multi-attachment email item into N separate items so the Google Drive node runs once per file instead of erroring after the first. {{$binary.keys().first()}}dynamically resolves each item's binary field name, replacing the hardcodedattachment_0that causes upload failures for every file beyond the first.{{$binary.values().first().fileName}}reads the original attachment filename from the binary metadata, enabling organized and searchable filenames in Google Drive rather than generic hardcoded strings.
Related Lessons
Next Steps
Continue your n8n journey with the full n8n AI Automation - Zero to Hero course.