Skip to content

Every 10 minutes

Save client email attachments into Drive, one folder per company

Attachments from client emails are filed in Drive automatically, each in a folder named after the sender's company.

Runs
Every 10 minutes
Apps
Gmail, Google Drive
AI
Not needed
Access
Gmail gmail.modify; Drive write

Send this to your assistant

Create a ClickRuntime automation: every 10 minutes, take attachments from emails labelled Clients and save them to Drive in a folder for each sender's company.

Paste it into your assistant. It tells you what it will send or change before it runs live.

First time? Adding ClickRuntime to your assistant takes about two minutes.

Why use it

Why teams use this automation

A small bookkeeping practice receives receipts, statements and signed forms by email from dozens of clients. Someone downloads each attachment and drags it into the right Drive folder, often days later, and a few always end up in Downloads.

Filing attachments as they arrive means every client's documents are already in their folder when the team sits down to work. Nobody has to search an inbox to find last month's statement.

What you get out of it

  • Documents are where the work happens

    The team works from Drive, so attachments belong there. Having them filed by company saves a search through email each time.

  • Nothing lost in Downloads

    Every attachment from a labelled email is saved, not just the ones someone remembered to download.

  • New clients get a folder automatically

    When a company emails for the first time, its folder is created. The structure grows with your client list.

  • Your inbox labels keep control

    Only emails you label Clients are processed. Personal mail and newsletters stay out of Drive.

How it works

What happens, step by step

  1. Every 10 minutes, ClickRuntime looks for new emails in Gmail with your Clients label.

  2. It works out the sender's company from their email address and finds or creates that company's folder in Drive.

  3. Each attachment is saved into the folder.

  4. The email is marked as done, so its attachments are not saved again.

Before it runs live

  • Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
  • Connect Google Drive

What you get

RunsEvery 10 minutes
Save client email attachments into Drive, one folder per companytoday, 9:00Succeeded
Google Drive · Clients/NorthwindSaved 2 files to Clients/Northwind: September-statement.pdf, signed-engagement-letter.pdf

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • Your own rules

    Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.

  • Any number of apps

    One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.

  • AI where it helps

    Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.

  • On a schedule or on each event

    Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.

Changes you can ask for

  • Act only on the items that match your own rules, and skip the rest
  • Add an AI step, for example to summarize, sort or draft a reply
  • Add another app, for example also send it to Slack
  • Combine it with other Gmail and Google Drive steps into one automation

Under the hood

The code that runs this automation

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
save_email_attachments_into_drive_folders.pyexample
import base64
from googleapiclient.http import MediaInMemoryUpload
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, report_fetched

PARENT_ID, DONE_LABEL = "your-clients-folder-id", "Label_saved"

@on_trigger
def run(event):
    creds = Credentials(credentials.connection("google", "work"))
    gmail, drive = build("gmail", "v1", credentials=creds, cache_discovery=False), build("drive", "v3", credentials=creds, cache_discovery=False)
    msgs = gmail.users().messages().list(userId="me", q="label:Clients has:attachment -label:saved").execute().get("messages", [])
    report_fetched(len(msgs))
    if not msgs:
        return {"saved": 0}
    for m in msgs:
        msg = gmail.users().messages().get(userId="me", id=m["id"]).execute()
        sender = next(h["value"] for h in msg["payload"]["headers"] if h["name"] == "From")
        company = sender.split("@")[-1].split(".")[0].rstrip(">").title()
        found = drive.files().list(q=f"name='{company}' and '{PARENT_ID}' in parents and trashed=false", fields="files(id)").execute()["files"]
        folder = found[0]["id"] if found else drive.files().create(body={"name": company, "parents": [PARENT_ID],
                 "mimeType": "application/vnd.google-apps.folder"}, fields="id").execute()["id"]
        for part in msg["payload"].get("parts", []):
            if part.get("filename") and part["body"].get("attachmentId"):
                data = gmail.users().messages().attachments().get(userId="me", messageId=m["id"], id=part["body"]["attachmentId"]).execute()
                drive.files().create(body={"name": part["filename"], "parents": [folder]},
                                     media_body=MediaInMemoryUpload(base64.urlsafe_b64decode(data["data"]), mimetype=part["mimeType"])).execute()
        gmail.users().messages().modify(userId="me", id=m["id"], body={"addLabelIds": [DONE_LABEL]}).execute()
    return {"saved": len(msgs)}

FAQ

Common questions

How does it decide the company name?
It uses the domain of the sender's email address, so mail from anyone at northwind.com goes to the Northwind folder. Free email addresses such as Gmail use the sender's name instead.
Will the same attachment be saved twice?
No. Once an email has been processed it is marked in Gmail and skipped on later checks.
Can I choose where the company folders live?
Yes. You pick one parent folder in Drive and all company folders are created inside it.
What permissions does it need?
Gmail gmail.modify; Drive write. Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run each time it checks. Checks that find nothing new and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

Set up “Save client email attachments into Drive, one folder per company” from your assistant

Copy the prompt above, or connect your assistant first. Free plan, no credit card.