Skip to content
Home ยป Blog ยป How to Automatically Save Gmail Attachments to Google Drive

How to Automatically Save Gmail Attachments to Google Drive

Save_Gmail_Attachments_to_Drive

If you’ve ever dug through hundreds of emails looking for one invoice, you already know why manually saving attachments is a losing game. I used to drag PDFs into Drive one by one until I finally set up an automated pipeline โ€” and honestly, it took less time to build than I expected. Below is exactly how I do it, plus a couple of backup methods in case Apps Script isn’t your thing.

What You’ll Need

You don’t need anything fancy for this โ€” just a Google account and a few minutes.

Before You Start

  • A Gmail account (personal or Google Workspace)
  • A Google Drive account with some free space
  • Five to ten minutes to copy and run one script

Step 1: Choose Your Automation Method

There are really three ways to pull this off, and which one you pick depends on how hands-on you want to be.

  • Google Apps Script โ€” free, fully customizable, runs on a schedule you control. This is the method I recommend and the one we’ll build below.
  • Zapier or Make โ€” no code, quick to set up, but the free tiers cap how many “tasks” run per month, which matters if you get a lot of email.
  • Third-party Gmail add-ons โ€” convenient, but you’re trusting another company with access to your inbox, and most charge a subscription after a trial.

I lean toward Apps Script because it’s free forever, lives entirely inside your own Google account, and you can tweak the logic any time you want. That’s the path we’ll walk through in detail.

๐Ÿ“ Note: If you’d rather skip the scripting entirely, jump to Step 4 for the no-code alternatives.

Step 2: Set Up the Apps Script

Here’s the part that sounds intimidating but really isn’t. Go to script.google.com and click New Project. Give it a name like “Gmail to Drive Saver” so you can find it later โ€” future you will thank present you.

Delete the placeholder code in the editor and paste this in instead:

function saveAttachmentsToDrive() {
  var folder = DriveApp.getFoldersByName('Gmail Attachments').hasNext()
    ? DriveApp.getFoldersByName('Gmail Attachments').next()
    : DriveApp.createFolder('Gmail Attachments');

  var threads = GmailApp.search('has:attachment -label:saved-to-drive');

  threads.forEach(function(thread) {
    var messages = thread.getMessages();
    messages.forEach(function(message) {
      var attachments = message.getAttachments();
      attachments.forEach(function(attachment) {
        folder.createFile(attachment);
      });
    });
    thread.addLabel(GmailApp.getUserLabelByName('saved-to-drive') ||
      GmailApp.createLabel('saved-to-drive'));
  });
}

This script does three things: it creates (or reuses) a folder called Gmail Attachments in your Drive, searches for messages with attachments that haven’t been processed yet, and labels each one saved-to-drive once it’s done โ€” that label is what stops the script from re-saving the same files over and over.

โš ๏ธ Warning: The first time you run this, click Run and Google will ask you to authorize the script. This is normal โ€” you’re just granting the script permission to read Gmail and write to Drive, both of which are your own accounts talking to each other.

Step 3: Automate It With a Trigger

Running the script manually defeats the whole purpose, so let’s set it to run on its own. In the Apps Script editor, click the clock icon on the left sidebar labeled Triggers, then click Add Trigger in the bottom right.

Set the function to run as saveAttachmentsToDrive, choose Time-driven as the event source, and pick Hour timer running every hour. I’ve found hourly checks strike the right balance โ€” frequent enough that files show up quickly, without hammering your quota.

๐Ÿ’ก Tip: If you only get a handful of attachments a day, switch the trigger to a daily timer instead. It’s one less thing running in the background, and you’ll barely notice the difference in how fast files land in Drive.

Step 4: Filter Which Emails Qualify

Saving every single attachment from every email is usually overkill โ€” you probably just want invoices, receipts, or messages from specific senders. You can narrow the search by editing the GmailApp.search() line in the script. For example, swapping in from:billing@yourvendor.com has:attachment restricts it to attachments from one sender only.

Prefer a no-code route instead? Both Zapier and Make offer a “New Attachment in Gmail” trigger connected to a “Upload File in Google Drive” action. The setup is mostly point-and-click, though I’d recommend adding a filter step so you’re not burning your monthly task quota on newsletter PDFs and marketing flyers.

Pro Tips & Common Mistakes

  • Forgetting the label check is the number one mistake I see โ€” skip it and the script re-saves the same attachments every single hour, quietly filling up your Drive.
  • Google Workspace accounts sometimes have Apps Script restricted by an admin. If the script won’t authorize, that’s usually why โ€” ask your workspace admin to allow it.
  • Large attachments (video files, big zip archives) can occasionally time out mid-save. If that happens, narrow your search query so the script processes fewer messages per run.
  • Duplicate folders pop up if you rename “Gmail Attachments” in Drive after the script has already run โ€” the script will just create a new one with the original name. Rename inside the script instead, if you want a different folder name.

โœ… Once your trigger is running, check back after a day or two and confirm new attachments are actually landing in the Drive folder. That’s your sign everything’s wired up correctly.

Wrapping Up

Once this is set up, you’re done thinking about it โ€” attachments quietly land in Drive without you lifting a finger. It genuinely feels like getting a small chunk of your week back. From here, you might want to set up a similar rule for expense receipts or explore Drive’s search filters to keep the saved files organized as the folder grows.