Last active
November 17, 2025 15:24
-
-
Save Avi-E-Koenig/3cee28794d2a2877943f7e2703f8575f to your computer and use it in GitHub Desktop.
google get all attachments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function saveAttachmentsFromSender() { | |
| const SENDER = "******"; | |
| const FOLDER_ID = "*******"; | |
| const folder = DriveApp.getFolderById(FOLDER_ID); | |
| const threads = GmailApp.search(`from:${SENDER} has:attachment`); | |
| let savedCount = 0; | |
| threads.forEach(thread => { | |
| const messages = thread.getMessages(); | |
| messages.forEach(msg => { | |
| const attachments = msg.getAttachments(); | |
| attachments.forEach(att => { | |
| const name = att.getName(); | |
| // Avoid duplicates | |
| const existing = folder.getFilesByName(name); | |
| if (existing.hasNext()) { | |
| Logger.log(`Skipping duplicate: ${name}`); | |
| return; | |
| } | |
| folder.createFile(att); | |
| savedCount++; | |
| Logger.log(`Saved: ${name}`); | |
| }); | |
| }); | |
| }); | |
| Logger.log(`Done. Total attachments saved: ${savedCount}`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment