In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a small code snippet that you have to copy/paste inside Google Apps Script editor to enable the transfer of Gmail Attachments (PDF & Images) to Google Drive.
First of all, visit the script.google.com URL and then click the “New Project” button to create a new project.
Within a few seconds, a new Google Apps Script project will be created for you.
Here’s how the next screen will look.
Here’s a source code that you just need to copy/paste inside the code.gs
file. This file is already opened in the Google Apps Script editor (as you can see in the above screenshot).
const saveGmailtoGoogleDrive = () => { const folderId = '1XsVZoyADqioGGMsFSuK27iqBSqbnaSY2'; const searchQuery = 'has:attachment'; const threads = GmailApp.search(searchQuery, 0, 10); threads.forEach(thread => { const messages = thread.getMessages(); messages.forEach(message => { const attachments = message.getAttachments({ includeInlineImages: false, includeAttachments: true }); attachments.forEach(attachment => { Drive.Files.insert( { title: attachment.getName(), mimeType: attachment.getContentType(), parents: [{ id: folderId }] }, attachment.copyBlob() ); }); }); }); };
Note:- Here you need to replace the value of const folderId
with the ID of your own Google Drive folder.
Now, it’s time to execute this script by clicking the “Run” button given in the editor.
After running the script, you will see that all the attachments inside your Gmail emails are automatically downloaded to Google Drive.
MiniMax-M1 is a new open-weight large language model (456 B parameters, ~46 B active) built with hybrid…
Managing Git hooks manually can quickly become tedious and error-prone—especially in fast-moving JavaScript or Node.js…
Git hooks help teams enforce code quality by automating checks at key stages like commits…
Choosing the right Git hooks manager directly impacts code quality, developer experience, and CI/CD performance.…
We evaluated the performance of Llama 3.1 vs GPT-4 models on over 150 benchmark datasets…
The manufacturing industry is undergoing a significant transformation with the advent of Industrial IoT Solutions.…