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.
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
Every 10 minutes, ClickRuntime looks for new emails in Gmail with your Clients label.
It works out the sender's company from their email address and finds or creates that company's folder in Drive.
Each attachment is saved into the folder.
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
Build your own
Need it to work differently?
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
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?
Will the same attachment be saved twice?
Can I choose where the company folders live?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Save invoice PDFs from Gmail to Drive, named by supplier and amount
Invoice and receipt PDFs in your inbox are saved to Drive as date_supplier_amount files, and the email is labelled as filed.
See how it worksTranscribe emailed audio and save summaries to Drive
Voice notes and recordings sent to your inbox become a transcript and summary in Drive, with the summary emailed to you.
See how it worksFile emailed CVs in Drive with a short candidate review
Every CV sent to your jobs inbox is saved to your Candidates folder and you get an email with a short review against the role.
See how it worksKeep exploring
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.