πŸ“ Gmail attachment backup to Google Drive

⚑ 3,234 views Β· πŸ“ File Management

Description

πŸ“₯ Gmail Attachment Backup to Google Drive β€” n8n Workflow

This n8n workflow automatically backs up email attachments from a specific sender in Gmail to a designated folder in Google Drive. It polls Gmail every minute and uploads any new attachments from matching emails to the specified Google Drive folder with a timestamped filename.


πŸ“Œ Use Case

Primary Purpose:

Ideal For:


🧭 Workflow Overview

Here’s how the workflow operates:

  1. πŸ”” Gmail Trigger
    Polls Gmail every minute for new messages from a specific sender (test@gmail.com).

  2. πŸ“© Gmail Get Message
    Retrieves the full contents (including attachments) of the matched email.

  3. 🧠 Code (JS)
    Iterates over all binary attachments in the email and restructures them as individual binary items to upload separately.

  4. πŸ“€ Google Drive
    Uploads each attachment to a target Google Drive folder (DOcs) with a timestamp and unique name.

  5. πŸ“ Replace Me (NoOp)
    Placeholder node to indicate workflow completion. You can replace this with Slack notifications, logs, or alerts.


πŸ”§ How to Use

Prerequisites

Setup Instructions

  1. Import the Workflow
    Copy and paste the workflow JSON into your n8n editor.

  2. Set Up Credentials
    Ensure the following credentials exist and are authorized:

    • `Gmail (for Gmail nodes)
    • `Google Drive (for Google Drive node)
  3. Configure the Folder
    Update the folderId in the Google Drive node if you want to use a different target folder.

  4. Activate the Workflow
    Enable the workflow in n8n. It will start polling Gmail every minute.


✏️ How to Customize

TaskHow to Customize
Change sender filterModify the sender field in the Gmail Trigger node
Adjust polling frequencyChange the pollTimes configuration in the trigger node
Change destination folderUpdate folderId in the Google Drive node
Modify filename formatEdit the name expression in the Google Drive node
Add post-upload logicReplace or extend the Replace Me node with notifications, logs, etc.
Process only specific attachmentsAdd logic in the Code node to filter by filename or MIME type

πŸ“‚ Filename Format Example

[MessageID]_[Timestamp]_backup_attachment

This naming convention ensures uniqueness and traceability back to the original message.


βœ… Future Improvements


πŸ’¬ Support

For any issues using this workflow:

πŸ”— Nodes Used

Google Drive, Gmail, Gmail Trigger

πŸ“₯ Import

Download workflow.json and import into n8n: Workflow menu β†’ Import from File

πŸ“– Importing guide Β· πŸ”‘ Credential setup