Free tool · Google Apps Script

Apps Script generator: save Gmail attachments to Google Drive

Gmail has no rule to save attachments to Drive automatically. A short Google Apps Script can do it for free. Choose your options below, copy the script, paste it into Apps Script and set a timer. Nothing is sent to us: the script runs only in your Google account.

Works with personal Gmail and Google Workspace · Gmail only (for Outlook or IMAP, see the end of the page)

1. Choose your options

Same syntax as the Gmail search box. Examples: has:attachment from:billing@supplier.com, has:attachment subject:invoice, has:attachment label:clients-acme. The script adds the "already saved" filter for you.

Created in My Drive if it does not exist.

The part after /folders/ in the folder's URL. Use it for shared drives.

Comma separated. Empty = every file type.

Filters out logos and signature images.

Used so nothing is saved twice.

2. Copy the script

3. Install it (about 5 minutes)

  1. Open Apps Script

    Go to script.google.com with the Google account whose Gmail you want to read, and click New project. Rename it, for example "Gmail attachments to Drive".

  2. Paste the code

    Delete the sample myFunction code in Code.gs, paste the script and save (Ctrl/Cmd + S).

  3. Run it once

    In the function menu at the top choose saveAttachments and click Run. Google asks for permission to read Gmail and manage Drive. Because it is your own script, Google shows "Google hasn't verified this app": click Advanced → Go to (project name) → Allow. Check the execution log and your Drive folder.

  4. Turn on the timer

    Choose installTrigger in the function menu and click Run. From now on the script runs automatically at the interval you picked. To stop it, run removeTrigger or delete the trigger in the clock icon (Triggers) on the left.

Tip: the first run only processes up to 50 conversations so it stays within Apps Script's 6-minute limit. If you have a large backlog, run saveAttachments a few times by hand, or let the timer catch up.

What the script does (and does not do)

Honest limits you should know about:

Script vs a dedicated tool

This Apps ScriptInbox2Drive
PriceFreeFree up to 10 documents/month; from €19/month
MailboxesThe Gmail account it runs inGmail, Outlook/Microsoft 365, any IMAP; several into one Drive
SortingBy the search you write, sender or monthAI reads each file: invoice, receipt, contract, payslip… (13 types)
Past emailsWhatever your search finds, 50 conversations per runHistorical import (up to 24 months on Pro)
DestinationGoogle DriveGoogle Drive, OneDrive or Dropbox
UpkeepYou maintain the codeNone

If the script covers your needs, use it: it is a good solution for one Gmail account and simple rules. If you need several inboxes, Outlook, or documents filed by type without writing a search for each, try Inbox2Drive free. More options compared in all 5 ways to save email attachments to Google Drive.

FAQ

Can Gmail save attachments to Google Drive automatically?

Not on its own. Gmail lets you save one attachment at a time with the Drive icon, but it has no rule that does it automatically. A Google Apps Script on a time trigger, a Gmail add-on, an automation platform or a dedicated tool can do it.

Is this Apps Script free?

Yes. Apps Script is included with every Google account. The script runs inside your own account, so your emails and files are not sent to us or anyone else. Google applies daily quotas, which are enough for most small inboxes.

How does the script avoid saving the same attachment twice?

After processing a conversation it adds a Gmail label (for example SavedToDrive) and the search excludes conversations with that label. Labels apply to whole conversations, so attachments in a reply that arrives later in an already labeled conversation are skipped.

Why does Google say the app is unverified when I authorize the script?

Scripts you write yourself are not reviewed by Google, so the consent screen shows a warning. Because you are the author and the only user, you can click Advanced and continue to the project. Only authorize scripts whose code you have read.

Can I save to a shared drive?

Yes: paste the shared drive folder's ID in the "folder ID" field. Your account needs permission to add files to that folder.

Does it work with Outlook?

No. Apps Script can only read the Gmail account it runs in. For Outlook see how to save Outlook attachments to Google Drive.

Related: All free tools · all 5 ways compared · Zapier alternative · cloudHQ alternative · Gmail add-ons compared · download all Gmail attachments at once · versión en español · for bookkeepers.

Rather not maintain a script?

Inbox2Drive connects Gmail, Outlook and IMAP, reads each attachment with AI and files it in the right Drive folder. Never sends or deletes your email.

Create a free account

Free plan · No credit card required