# How to save Gmail attachments to Google Drive automatically

> Published 2026-12-01
> Source: https://viktor.com/blog/save-gmail-attachments-to-google-drive

Ask Viktor, the [AI employee](https://viktor.com/ai-employee), in Slack or Microsoft Teams, and he sets up a Gmail trigger that files matching attachments into your Drive folder. On your own, create a Gmail filter that labels matching mail to-drive (for example `from:billing@acme-supplier.com has:attachment`), create the Drive folder, paste a Google Apps Script with its folder ID at script.google.com, authorize it and add an hourly time-driven trigger. Then send a test email and check the folder after the next run.

## Compare the ways to save Gmail attachments to Drive

Viktor, Google Apps Script, Zapier and n8n can all save attachments as they arrive; Gmail’s own Add to Drive button saves the attachment you click. The differences are how you set the rule up and whether it reaches mail you already have.

```json:object
{
  "_key": "k18",
  "_type": "table",
  "rows": [
    {
      "_key": "k12",
      "_type": "tableRow",
      "cells": [
        "Method",
        "How you set it up",
        "Filter by sender, label or keyword",
        "Attachments already in your inbox",
        "Cost shape (read 1 Dec 2026)"
      ]
    },
    {
      "_key": "k13",
      "_type": "tableRow",
      "cells": [
        "Viktor",
        "Describe the rule in Slack, Microsoft Teams or the web app; he sets up a Gmail trigger or a scheduled task and test-fires it",
        "Gmail search operators, through his Find Emails tool",
        "Yes: the same search runs over older mail",
        "Credits, see Viktor pricing"
      ]
    },
    {
      "_key": "k14",
      "_type": "tableRow",
      "cells": [
        "Google Apps Script",
        "Paste a script, authorize it and add a time-driven trigger",
        "Any Gmail search query in GmailApp.search",
        "Yes: the search covers your whole mailbox",
        "Runs under Apps Script quotas for your account type"
      ]
    },
    {
      "_key": "k15",
      "_type": "tableRow",
      "cells": [
        "Zapier",
        "Build a Zap from Gmail’s New Attachment trigger to Google Drive’s Upload File action",
        "A Filter by Zapier step, or a labeled-email trigger",
        "No: attachments on older emails will not trigger",
        "Free plan with two-step Zaps; multi-step Zaps under Professional"
      ]
    },
    {
      "_key": "k16",
      "_type": "tableRow",
      "cells": [
        "n8n",
        "Build a workflow from the Gmail Trigger node to the Google Drive node’s Upload a file operation",
        "Label, Search and Sender filters on the trigger",
        "The trigger fires for new messages at each poll",
        "n8n Cloud plans, or the self-hosted Community Edition on GitHub"
      ]
    },
    {
      "_key": "k17",
      "_type": "tableRow",
      "cells": [
        "Gmail Add to Drive",
        "Hover over an attachment and click Add to Drive",
        "You pick the email",
        "You click each attachment",
        "Built into Gmail"
      ]
    }
  ]
}
```

Sources: [Gmail trigger](https://viktor.com/docs/event-triggers), [scheduled task](https://viktor.com/docs/scheduled-tasks), [Find Emails](https://viktor.com/integrations/gmail), [Viktor pricing](https://viktor.com/pricing), [time-driven trigger](https://developers.google.com/apps-script/guides/triggers/installable), [GmailApp.search](https://developers.google.com/apps-script/reference/gmail/gmail-app), [Apps Script quotas](https://developers.google.com/apps-script/guides/services/quotas), [New Attachment](https://zapier.com/apps/gmail/integrations/google-drive), [Upload File](https://zapier.com/apps/google-drive/integrations), [attachments on older emails will not trigger](https://zapier.com/apps/gmail/integrations/google-drive), [Free plan with two-step Zaps; multi-step Zaps under Professional](https://zapier.com/pricing), [Gmail Trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.gmailtrigger/), [Upload a file](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googledrive/file-operations/), [n8n Cloud plans, or the self-hosted Community Edition on GitHub](https://n8n.io/pricing/), [Add to Drive](https://support.google.com/mail/answer/30719?hl=en)

Sources: [Gmail trigger](https://viktor.com/docs/event-triggers), [scheduled task](https://viktor.com/docs/scheduled-tasks), [Find Emails](https://viktor.com/integrations/gmail), [Viktor pricing](https://viktor.com/pricing), [time-driven trigger](https://developers.google.com/apps-script/guides/triggers/installable), [GmailApp.search](https://developers.google.com/apps-script/reference/gmail/gmail-app), [Apps Script quotas](https://developers.google.com/apps-script/guides/services/quotas), [New Attachment](https://zapier.com/apps/gmail/integrations/google-drive), [Upload File](https://zapier.com/apps/google-drive/integrations), [attachments on older emails will not trigger](https://zapier.com/apps/gmail/integrations/google-drive), [Free plan with two-step Zaps; multi-step Zaps under Professional](https://zapier.com/pricing), [Gmail Trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.gmailtrigger/), [Upload a file](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googledrive/file-operations/), [n8n Cloud plans, or the self-hosted Community Edition on GitHub](https://n8n.io/pricing/), [Add to Drive](https://support.google.com/mail/answer/30719?hl=en)

Viktor is the better fit when you would rather describe the rule than build it. One message covers the filter, the folder layout and the file names; he runs the same search over the attachments already in your inbox; and he [test-fires a new trigger](https://viktor.com/docs/event-triggers) before it goes live, by default with writes to your integrations blocked, then shows you the result.

Apps Script fits when you want the whole job inside your Google account and are comfortable editing code. Zapier and n8n fit when your team already keeps its workflows there.

## Save Gmail attachments to Drive with Viktor

Viktor is the AI employee who lives in Slack and Microsoft Teams, connects to [9,800+ tools](https://viktor.com/integrations), and does the work. For this job he uses [Gmail](https://viktor.com/integrations/gmail) and [Google Drive](https://viktor.com/integrations/google-drive): Gmail’s Find Emails and Download Attachment tools, and Drive’s Create folder, Upload and Rename tools.

1. **Connect Gmail and Google Drive.** Both connect with Sign in with Google. In Slack and Microsoft Teams workspaces, set the Gmail account to Private (Invite only) on its [Access tab](https://viktor.com/docs/integration-permissions), so teammates can’t use your mailbox through Viktor. Tasks a person creates run as that person and keep access to their private connections.
2. **Switch off what the job doesn’t need.** On each account’s Tools tab, a tool set to Off can’t be used. Set Google Drive’s Delete and Gmail’s Send Email to Off if filing is all you want.
3. **Describe the rule.** Name the senders or label, the folder, the subfolder layout and the file name.
4. **Confirm the test.** Viktor checks for an existing trigger, creates it and test-fires it; confirm before he runs a test with real side effects.
5. **Fill in the backlog.** Ask him to run the same search once over older mail and file what it finds.

A request for steps 3 to 5 can look like this:

```
@Viktor every time an email with a PDF from billing@acme-supplier.com reaches my Gmail, save the PDF to the Drive folder "Finance / Supplier invoices". Put each file in a subfolder for the month it arrived (2026-11), name it 2026-11-28_acme_original-file-name.pdf, and post the Drive link in #finance. Then do the same once for every matching email since January.
```

This request is an example and has not been run end to end. Test it on one label and a sample message before you rely on it.

Two timing notes from Viktor’s docs. [Gmail triggers](https://viktor.com/docs/event-triggers) are checked by the provider on a schedule and can take up to 15 minutes to fire. And each event can start its own AI run, so if checking every so often is good enough, a [scheduled task](https://viktor.com/docs/scheduled-tasks) is usually cheaper. Viktor warns you when an AI task would run more than about six times a day, and he can add a condition script that skips a run when nothing new has arrived. Each AI run uses credits, and [calls Viktor makes to some of your connected apps are added up and charged once a day](https://viktor.com/help/category/credits/how-credits-work).

[Have Viktor file your Gmail attachments in Drive (up to $100 in free credits) →](https://app.viktor.com/signup)

## Save Gmail attachments to Drive with Google Apps Script

Google describes [Apps Script](https://developers.google.com/apps-script/overview) as a platform with a browser-based code editor that saves scripts to Google Drive and runs them on Google’s servers. The script below saves attachments from one Gmail label into month subfolders of one Drive folder, then labels each thread as done.

1. In Gmail, create two labels: to-drive and saved-to-drive. Add a [filter](https://support.google.com/mail/answer/6579?hl=en) that sends matching mail to the to-drive label.
2. In Drive, open the destination folder and copy the ID at the end of its address.
3. Go to [script.google.com](https://developers.google.com/apps-script/guides/projects), click New Project and paste the code.
4. Replace PASTE_FOLDER_ID with the folder ID and save.
5. Run createTrigger once. Apps Script [asks you to authorize](https://developers.google.com/apps-script/guides/services/authorization) the access it needs, then runs saveLabeledAttachments every hour.

```
// Not run end to end: test on one labeled sample message first.
const LABEL = 'to-drive';
const DONE_LABEL = 'saved-to-drive';
const FOLDER_ID = 'PASTE_FOLDER_ID';

function saveLabeledAttachments() {
  const root = DriveApp.getFolderById(FOLDER_ID);
  const done = GmailApp.getUserLabelByName(DONE_LABEL) || GmailApp.createLabel(DONE_LABEL);
  const query = 'label:' + LABEL + ' has:attachment -label:' + DONE_LABEL;
  const threads = GmailApp.search(query, 0, 20);
  for (const thread of threads) {
    for (const message of thread.getMessages()) {
      const month = Utilities.formatDate(message.getDate(), Session.getScriptTimeZone(), 'yyyy-MM');
      const folder = getOrCreateFolder(root, month);
      for (const attachment of message.getAttachments({includeInlineImages: false})) {
        const blob = attachment.copyBlob();
        blob.setName(month + '_' + attachment.getName());
        folder.createFile(blob);
      }
    }
    thread.addLabel(done);
  }
}

function getOrCreateFolder(parent, name) {
  const found = parent.getFoldersByName(name);
  return found.hasNext() ? found.next() : parent.createFolder(name);
}

function createTrigger() {
  ScriptApp.newTrigger('saveLabeledAttachments').timeBased().everyHours(1).create();
}
```

Three things to know before you switch it on:

- **Access.** The Gmail methods the script uses require the `https://mail.google.com/` scope, listed on Google’s [GmailApp reference](https://developers.google.com/apps-script/reference/gmail/gmail-app). Google’s [Gmail scopes page](https://developers.google.com/workspace/gmail/api/auth/scopes) describes that scope as access to read, compose, send, and permanently delete all your email from Gmail, so the script reaches the whole mailbox, not one label.
- **Limits.** Google’s [quotas page](https://developers.google.com/apps-script/guides/services/quotas) lists a script runtime of 6 min per execution, and a total trigger runtime of 90 min a day for consumer accounts such as gmail.com and 6 hr a day for Google Workspace accounts. The batch of 20 threads per run keeps each run short; raise it carefully.
- **Replies.** Google’s [labels help](https://support.google.com/mail/answer/118708?hl=en) says that with conversation view on, a label applies only to the existing messages, not to new replies. If your filter labels a reply with an attachment to-drive, the next run can pick up the whole thread and save its earlier attachments a second time.

`getAttachments({includeInlineImages: false})` leaves out images pasted into the email body; the [GmailMessage reference](https://developers.google.com/apps-script/reference/gmail/gmail-message) lists that option. To sort by sender instead of month, build the subfolder name from `message.getFrom()`.

## Save Gmail attachments to Drive with Zapier

Zapier’s [Gmail and Google Drive page](https://zapier.com/apps/gmail/integrations/google-drive) lists ready-made templates, among them “Save new Gmail attachments to Google Drive”, built from Gmail, Filter by Zapier and Google Drive, and “Save new attachments from labeled emails in Gmail to Google Drive”, built from Gmail and Google Drive.

The trigger is Gmail’s New Attachment, which Zapier describes as firing “when you receive a new attachment”. The action is Google Drive’s [Upload File](https://zapier.com/apps/google-drive/integrations), and Zapier’s Google Drive page says you can automate files in both personal Google Drive and Shared Drives.

Two limits come from Zapier’s pages. The New Attachment trigger only finds emails received in the last hour on each check, so attachments on older emails will not trigger. And Zapier’s [pricing page](https://zapier.com/pricing) lists two-step Zaps among the Free plan’s key features and multi-step Zaps under Professional. The first template adds Filter by Zapier as a third app between Gmail and Google Drive; the labeled-email template uses two. Zapier also lists Zapier Copilot among the Free plan’s key features.

## Save Gmail attachments to Drive with n8n

n8n’s [Gmail Trigger](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.gmailtrigger/) node has one event, Message Received, which triggers for new messages at the poll time you set. Its filters cover labels, a Gmail search and a sender. The [Google Drive node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.googledrive/file-operations/) has an Upload a file operation for the second step.

On [n8n’s pricing page](https://n8n.io/pricing/), the hosted product is n8n Cloud with a free trial, and “A standard, self-hosted version of n8n is available on GitHub” as the Community Edition.

## Filter by sender, label or keyword

Viktor’s Find Emails, the script’s GmailApp.search and n8n’s Search filter all take Gmail’s [search operators](https://support.google.com/mail/answer/7190?hl=en). The ones that matter for attachments:

- `has:attachment` finds messages that carry an attachment.
- `from:billing@acme-supplier.com` limits the rule to one sender.
- `label:to-drive` limits it to mail a filter has labeled.
- `filename:pdf` matches an attachment name or type.
- `after:2026/01/01` sets the start date for a backlog run.
- `larger:10M` finds large messages.

A Gmail filter can do the sorting before any tool sees the mail. Gmail’s [filter rules](https://support.google.com/mail/answer/6579?hl=en) can send matching email to a label, archive it, star it or forward it. That is also the answer to moving mail into a folder automatically: Gmail uses labels, which Google notes [are different from folders](https://support.google.com/mail/answer/118708?hl=en), and a filter that applies a label and archives the message takes it out of the inbox.

## Name the files and build the folder structure

Decide the layout before the first file lands, because a tool will follow it on every run.

1. **One root folder per job**, such as “Finance / Supplier invoices”, owned by the account that runs the rule.
2. **Subfolders by one key**: the month the email arrived, the sender’s domain or the client. Pick one; mixing keys makes files hard to find.
3. **Create missing subfolders on the fly.** The script’s getOrCreateFolder does this with Drive’s [createFolder](https://developers.google.com/apps-script/reference/drive/folder) method; Viktor uses Drive’s Create folder tool.
4. **A file name that sorts**: date first, then sender, then the original file name, such as 2026-11-28_acme_invoice-4471.pdf. Keep email subjects out of file names when they carry customer details.

Keep the original attachment name in the new name, so two files from the same day stay apart.

## Keep Gmail and Drive access tight

Saving attachments needs read access to your mail and write access to a folder, and each method asks for it differently.

- **Folder sharing.** Google Drive’s [sharing help](https://support.google.com/drive/answer/7166529?hl=en) says that when you share a folder, all files and subfolders inside it inherit those same sharing permissions. Every saved attachment is visible to everyone who can see the folder, so file sensitive documents into a folder only the right people can open.
- **Mailbox scope.** Apps Script’s Gmail methods ask for the full-mailbox scope above. Viktor connects with Sign in with Google, and his Gmail connection can be limited to you on its Access tab.
- **Workspace accounts.** In Google Workspace, admins [control which third-party and internal apps can access Google Workspace data](https://support.google.com/a/answer/7281227?hl=en), with access settings such as Trusted, Limited, Specific Google data or Blocked. Check with your admin before connecting a work mailbox.
- **Credentials.** Sign in on each provider’s own consent screen; don’t paste passwords or tokens into a chat.

Start with one sender or one label, check the first week of saved files against the inbox, then widen the rule.

## Frequently asked questions

### Can I save Gmail attachments to Drive for free without Zapier?

Google Apps Script is the route without a third-party service. Google’s [quotas page](https://developers.google.com/apps-script/guides/services/quotas) sets its limits for consumer accounts such as gmail.com as well as for Google Workspace accounts, so the script above runs from a personal Gmail account too. If you do use Zapier, its [Free plan](https://zapier.com/pricing) lists two-step Zaps, such as New Attachment to Upload File without a filter step.

### How do I save only attachments from specific senders or Gmail labels?

Put the condition in a Gmail search: `from:` for a sender, `label:` for a label, `has:attachment` to skip mail without files ([search operators](https://support.google.com/mail/answer/7190?hl=en)). In the script, change the query line; with Viktor, name the senders or label in your request; in Zapier, use the labeled-email template or a Filter by Zapier step.

### How do I choose the Drive folder and name the saved files so they stay organized?

Use one root folder per job, subfolders by one key such as month or sender, and file names that start with the date and keep the original name. The script builds month subfolders with Drive’s [createFolder](https://developers.google.com/apps-script/reference/drive/folder) and renames each copy with `setName`; Viktor follows the layout and names you give him.

### How do I auto move to a folder in Gmail?

Gmail uses labels, which [are different from folders](https://support.google.com/mail/answer/118708?hl=en). Create a [filter](https://support.google.com/mail/answer/6579?hl=en) from a search, choose to apply a label and to archive the message, and matching mail moves out of the inbox into that label.

### Is there a way to save all attachments from an email at once?

Gmail’s help page describes [Add to Drive](https://support.google.com/mail/answer/30719?hl=en) as a button on an attachment: hover over it and click Add to Drive. The script saves every attachment on each matching message, because `getAttachments` returns all of them, and Viktor files each attachment on the emails that match your rule.

### Can I save the attachments already sitting in my inbox, not just new ones?

Yes, with a search-based method. The script’s Gmail search covers older mail that carries the to-drive label, and running it a few times works through a backlog in batches of 20 threads. Viktor can run the same search once over older mail with `after:` and `before:` dates. Zapier’s New Attachment trigger [does not trigger on attachments on older emails](https://zapier.com/apps/gmail/integrations/google-drive).

### Do I need a paid plan to keep the automation running?

Apps Script works within Google’s daily [quotas](https://developers.google.com/apps-script/guides/services/quotas) for your account type. On Zapier, the [Free plan](https://zapier.com/pricing) lists two-step Zaps, and multi-step Zaps are listed under Professional; Zapier’s template that puts Filter by Zapier between Gmail and Google Drive uses three apps.

Viktor runs the filing job on credits: each AI run of a trigger or scheduled task uses them, and a scheduled task with a condition script skips runs when nothing new has arrived ([scheduled tasks](https://viktor.com/docs/scheduled-tasks)).

## Hand the filing job to Viktor

Understanding [what an AI employee is](https://viktor.com/blog/what-is-an-ai-employee) explains the difference from a script or a Zap: you hand Viktor the filing job and its rules, and he posts the Drive links where you asked. Start with one sender or one label. [Give Viktor your attachment filing job (up to $100 in free credits) →](https://app.viktor.com/signup)