How to Save Gmail Attachments to Google Drive Automatically
Save Gmail attachments to Google Drive automatically for free with a short Apps Script, or with Zapier. Steps, code, limits and fixes. Checked 12 Oct 2026.
Quick answer: The fastest free method is a short Google Apps Script that checks Gmail on a schedule and copies new attachments into a Drive folder. Free? Yes. Time: about 10 minutes to set up.
If you would rather not touch code, Zapier can do the same job. Its Free plan allows two-step Zaps and 100 tasks a month, as of 12 October 2026.
What do you need before you start?
You need three things:
- A Google account with Gmail and Google Drive. Personal Gmail accounts work. Work or school accounts work unless your administrator blocks scripts.
- A Drive folder where the files will land. Create one now, for example "Gmail attachments".
- About 10 minutes, and permission to approve the script to read your Gmail and write to Drive.
The script needs two permissions. Gmail methods require the https://mail.google.com/ scope, according to Google's GmailApp reference. Creating a file in Drive needs the https://www.googleapis.com/auth/drive scope, according to Google's Folder reference. In plain terms: the script can read your mail and edit your Drive. It only runs under your account.
How do you save Gmail attachments to Google Drive automatically? (Method 1: Apps Script, free)
Use a script that searches Gmail for messages with attachments, saves each file to a folder, then labels the thread so it is not processed twice.
- Open your Drive folder. Verify this step: the menu may differ. The folder ID is the long string of letters and numbers at the end of the folder's web address. Copy it.
- Go to script.google.com and start a new Apps Script project.
- Delete the sample code in the editor.
- Paste the script below.
- Replace
PASTE_YOUR_FOLDER_ID_HEREwith the folder ID you copied. - Click Save, then choose the function
saveAttachmentsand click Run. - When Google asks you to approve access, review the permissions and allow them. Verify this step: the menu may differ. The wording of the approval screens can change.
- Check your Drive folder. Attachments from your recent emails should appear.
// Saves attachments from Gmail threads to a Drive folder.
// Labels each processed thread so it is not saved twice.
const FOLDER_ID = 'PASTE_YOUR_FOLDER_ID_HERE';
const LABEL_NAME = 'saved-to-drive';
const MAX_THREADS = 20;
function saveAttachments() {
const folder = DriveApp.getFolderById(FOLDER_ID);
const label =
GmailApp.getUserLabelByName(LABEL_NAME) || GmailApp.createLabel(LABEL_NAME);
// Emails that have an attachment and are not yet labeled.
const query = 'has:attachment -label:' + LABEL_NAME;
const threads = GmailApp.search(query, 0, MAX_THREADS);
threads.forEach(function (thread) {
thread.getMessages().forEach(function (message) {
// Skip small inline images such as logos and signatures.
const attachments = message.getAttachments({ includeInlineImages: false });
attachments.forEach(function (attachment) {
folder.createFile(attachment);
});
});
thread.addLabel(label);
});
}
The query has:attachment is a standard Gmail search operator, listed on Gmail's search help page. The -label: part excludes anything already labeled. GmailApp.search(query, start, max) returns at most max threads, as described in Google's reference. That is why this script handles 20 threads per run.
The setting includeInlineImages: false is documented in the GmailMessage reference. It defaults to true, so the script turns it off to avoid saving signature logos.
How do you make it run on its own?
Add a time-driven trigger so the script runs without you.
- In the Apps Script editor, click Triggers on the left.
- Click Add Trigger at the bottom right.
- Choose the function
saveAttachments. - Choose a time-based trigger and set how often it runs, such as every few hours.
- Click Save.
These menu names come from Google's installable triggers guide, which lists the steps as: click Triggers, click Add Trigger, configure the trigger, click Save. The guide also says installable triggers run under the account of the person who created them.
If you prefer code, run this once instead:
function createTrigger() {
ScriptApp.newTrigger('saveAttachments')
.timeBased()
.everyHours(6)
.create();
}
Google's own example uses the same pattern with everyHours(6). If you use everyMinutes(n) instead, n must be 1, 5, 10, 15 or 30, according to the ClockTriggerBuilder reference. Run createTrigger only once, or you will create duplicate triggers.
What if you only want certain attachments?
Change the query line. The filename: operator finds attachments with a certain name or file type, with examples such as filename:pdf, per Gmail's help page. For example, has:attachment filename:pdf -label:saved-to-drive saves only PDFs. Add from: or label: filters the same way.
Method 2: How do you do it with Zapier (no code)?
Zapier connects Gmail to Drive with a "Zap". The trigger is New Attachment in Gmail, and the action is Upload File in Google Drive, according to Zapier's tutorial (most recently updated April 2025).
- Create a Zap. Choose Gmail as the trigger app and New Attachment as the event.
- Sign in to Gmail and click Continue.
- Pick the mailbox or label. Keeping Inbox and All Labels checks every email you receive.
- Keep
-in:sentin the Search String so only received attachments are saved. - Click Test trigger, pick a test record, and continue.
- For the action, choose Google Drive and Upload File. Connect your account.
- Choose the Drive and folder, keep the file set to Attachment, and set a File Name.
- Click Test step and check Drive for the file.
Zapier's template adds a Filter by Zapier step between the trigger and the action. That makes three steps. The Free plan is listed as "Two-step", and Filters & Paths are not included on it, according to Zapier's pricing page as of 12 October 2026. The tutorial's label variant has no filter step: you pick the label in the trigger, which keeps the Zap at two steps.
Method 3: Can you just save one attachment by hand?
Yes. For a one-off file, hover over the attachment in the email and click the Google Drive icon, then use Organize to choose a folder, as Zapier's tutorial describes. This needs no setup but does not run automatically.
Which method should you choose?
| Method | Cost | Difficulty | Limits | Best for |
|---|---|---|---|---|
| Apps Script | Free | Medium (paste code) | 6 min per run, 90 min/day trigger time on consumer accounts | Steady, long-term use |
| Zapier | Free plan, then paid | Easy (no code) | Free: 2 steps, 100 tasks/month, 15 min checks | People who dislike code |
| Manual Drive icon | Free | Easiest | You must click each time | Occasional files |
Pick Apps Script if you receive attachments regularly and want to pay nothing. Pick Zapier if you want a visual builder and can live with the limits or pay.
What's free and what costs money?
Prices and limits below are as of the dates shown.
- Apps Script: Free. Limits as of Google's quota page (updated 3 September 2026): script runtime is 6 minutes per execution on both account types; trigger total runtime is 90 minutes per day for consumer accounts and 6 hours per day for Google Workspace; 20 triggers per user per script. Google says quotas can change.
- Zapier Free (as of 12 October 2026): 100 tasks per month, two-step Zaps, 15-minute polling.
- Zapier Professional (as of 12 October 2026): starts at 750 tasks per month, at $19.99 a month billed annually or $29.99 billed monthly, with a 14-day free trial, per Zapier's pricing page. Prices are the company's own.
Zapier's New Attachment trigger runs once per attachment, not once per email, according to the tutorial's description of the trigger, so a heavy inbox can use up 100 tasks quickly.
What can go wrong, and how do you fix it?
- "Exception: Unexpected error while getting the method or property getFolderById." The folder ID is wrong or your account cannot open the folder. Google says
getFolderByIdthrows an error if the folder does not exist or you lack permission. Re-copy the ID and check you own or can edit the folder. - Nothing appears in Drive. Check Gmail for a label called
saved-to-drive. If every matching thread already has it, the script has nothing new to do. Remove the label from a test thread and run again. - The script stops before finishing. A single run is limited to 6 minutes. Lower
MAX_THREADSor run the script more often. - Duplicate files. You may have created more than one trigger. Open Triggers and delete extra rows. Also, a thread with several messages is saved as a whole once labeled, so do not remove labels unless you want a re-save.
- Files with the same name pile up. Drive allows several files with one name. Add the date to the name if you want order, for example by creating a blob copy with a new name before saving.
- Old emails are not saved. The script handles 20 threads per run, newest first, so a big backlog takes several runs. Run it by hand a few times to catch up.
Is this allowed?
Yes, for your own mailbox. You are using Google's own scripting service on your own account, and the script runs under the account that created the trigger. Zapier uses an approved connection that you authorize.
Two cautions apply. If the mailbox belongs to your employer or school, check the policy before copying company files to a personal Drive. And attachments may contain other people's personal data, so keep the destination folder private.
What's still unclear?
- Quotas can change. Google states quotas may change, so check its quota page if your script hits limits.
- Authorization screen wording. The exact text of Google's approval screens can change, which is why that step is flagged.
- Large mailboxes. The script is built for new mail. Backfilling years of attachments may need many runs.
- Weakest point of Method 1. It requires pasting code, and a Google change to quotas or scopes could affect it.
Last checked: 12 October 2026.
Frequently asked questions
Can I save Gmail attachments to Google Drive automatically for free?
Yes. A Google Apps Script attached to your own Google account costs nothing and can run on a schedule. Zapier also has a free plan, but it is limited to two-step Zaps and 100 tasks a month as of 12 October 2026, so the Apps Script method is the better free option for steady use.
How often will the script check for new attachments?
You choose. In the Apps Script trigger settings you can run it every few hours or once a day. Google's documentation shows a time-driven trigger such as every 6 hours. The minutes option only accepts 1, 5, 10, 15 or 30. Consumer accounts also have a daily trigger runtime limit of 90 minutes.
Will the script save the same attachment twice?
Not with the script in this guide. After it saves a thread's attachments, it adds a Gmail label to that thread, and the search skips any thread that already has the label. If you remove the label from a thread, the script will save its attachments again.
Does this work with a work or school Google Workspace account?
Usually yes, but an administrator can restrict Apps Script or Drive access. Workspace accounts get higher daily limits than consumer accounts: 6 hours of trigger runtime per day instead of 90 minutes, according to Google's quota page. If a permission prompt is blocked, ask your admin.
Why did the script stop partway through?
Apps Script stops any single run after 6 minutes, and consumer accounts have a daily trigger runtime budget of 90 minutes. A large backlog of old emails can hit these limits. The script in this guide handles up to 20 threads per run, so it catches up over several runs.
Sources
- Apps Script quotas, Google for Developers (2026-09-03)
- Class GmailApp, Google for Developers (2026-10-12)
- Class GmailMessage, Google for Developers (2026-10-12)
- Class Folder (Drive service), Google for Developers (2026-10-12)
- Installable triggers, Google for Developers (2026-09-03)
- Class ClockTriggerBuilder, Google for Developers (2026-04-13)
- Refine searches in Gmail, Gmail Help (2026-10-12)
- Create rules to filter your emails, Gmail Help (2026-10-12)
- How to save Gmail attachments to Google Drive, Zapier (2025-04-01)
- Zapier pricing, Zapier (2026-10-12)