ByteChef logo
ByteChef
tutorials

Automatically Saving Email Attachments to Google Drive

Automatically Saving Email Attachments to Google Drive
4 min read
Petra Pažanin

Handling email attachments manually is a repetitive operational task common across many industries. Each time a new email arrives, users often need to download its attachments, sort them into folders, upload the files to a cloud drive, and repeat this process throughout the day. Although the task is simple, the accumulated time spent on it can become significant, especially for teams that process large volumes of email.

To streamline this process, we created a ByteChef workflow template that automatically checks for new emails and uploads their attachments directly to a specified Google Drive folder. The workflow is fully automated and runs in the background once configured.

This blog explains the purpose of the workflow, what problem it solves, and how it operates step by step.

Problem & Solution

Many teams receive documents such as invoices, patient records, reports, contracts, or user-submitted forms via email. Storing these documents consistently in Google Drive requires several manual steps:

  • Checking the inbox
  • Opening each email
  • Downloading attachments
  • Navigating to the correct Drive folder
  • Uploading files
  • Repeating for every email

When this happens dozens or hundreds of times per week, the time cost becomes non-trivial, and errors such as missed files or mis-sorted documents are more likely.

This workflow automates the entire process of detecting new emails while checking whether they include attachments, and if so, the attachments are uploaded to Google Drive. The result is a consistent, repeatable flow that eliminates manual file handling and mistakes.

Workflow Overview

The workflow consists of four key components:

  1. Trigger: new email detection
  2. Email retrieval: fetching email metadata and attachments
  3. Conditional check: verifying that the email contains one or more attachments
  4. Loop: uploading each attachment to Google Drive
Email Attachments to Google Drive Workflow

1. Trigger: email polling

The workflow begins with the googleMail_1/newEmailPolling trigger. This component periodically checks the connected Gmail inbox for new incoming messages. When a new message is detected, its ID is passed to the next component.

Gmail Trigger Configuration
  • Trigger label recommendation: Check for New Emails
  • Parameters: none (default polling behavior)

2. Retrieve email details

Next, the workflow uses the googleMail_1/getMail module to fetch the contents of the email associated with the trigger-provided ID. This retrieves sender information, subject, message body and attachment metadata. The attachments field returned from this step is especially important for downstream logic.

Get Email Data Configuration
  • Label recommendation: Get Email Data

  • Key parameter settings:

    1. format: SIMPLE
    2. id: ${trigger_1.id}

3. Conditional Check for Attachments

To avoid unnecessary operations for emails without files, a conditional step is used.

Conditional Check for Attachments Configuration
  • Label recommendation: Check for Attachments

  • Expression:

=size(${googleMail_1.attachments}) != 0

This evaluates whether the list of attachments contains at least one item. It ensures efficient execution and prevents empty loops.

a) If false → workflow stops (no attachments to process)

b) If true → workflow proceeds to process files

4. Looping Through Attachments

When attachments are present, the workflow iterates over each file using a loop module. During each iteration, loop_1.item contains the current file's metadata and binary content. Inside the loop, the workflow uploads each attachment to Google Drive.

Loop Through Attachments Configuration
  • Label recommendation: Loop Through Attachments

  • Loop items: ${googleMail_1.attachments}

5. Uploading Files to Google Drive

Each file is uploaded via the googleDrive_1/uploadFile component. This action performs a direct upload of the original file, preserving its name and format. Once completed, all attachments from the email are stored in the designated Drive folder without manual intervention.

Upload Attachment to Drive Configuration
  • Label recommendation: Upload Attachment to Drive

  • Key parameters:

    1. fileEntry: ${loop_1.item}
    2. folderId: 2025 (ID of the target Drive folder)

Workflow Summary

StepComponentPurpose
1Gmail TriggerDetect new incoming email
2Get Email DataRetrieve message details and attachments
3ConditionEnsure attachments exist before processing
4LoopIterate through all attachments
5Drive UploadSave each file in Google Drive

This modular structure makes the workflow easy to understand and modify - adding renaming logic, routing files to different folders, or notifying team members.

Possible Enhancements

Depending on use case, teams may extend the workflow with additional steps:

  • rename files using metadata (e.g., timestamp or sender)
  • sort files into subfolders based on rules
  • send Slack or email confirmations
  • create logs in a spreadsheet
  • apply AI-based classification to attachments

ByteChef's modular design allows these additions with minimal configuration.

Conclusion

This workflow template provides a straightforward and reliable way to automate the storage of email attachments in Google Drive. It removes manual downloading and uploading steps, reduces errors, and ensures documents are consistently archived.

Because it uses a small number of components and straightforward logic, it can be implemented quickly by both technical and non-technical users. The workflow is especially useful in environments that process large volumes of email-based documentation.