I'm trying to get the following to work but no matter what I do I get the same error:
ErrorTypeError: Cannot read properties of null (reading 'getThreads')
I would really like it to pull it from the emails in the Inbox but that didn't work so had to move thousands of emails to a "label"Also made sure the script is actually in the shared drive folder SOS Applicant Email Attachments.Here's the code:
function saveGmailAttachmentsToDrive() { var label = GmailApp.getUserLabelByName("SaveToDriveAttachments"); var threads = label.getThreads(); var folder = DriveApp.getFoldersByName("SOS Applicant Email Attachments").next(); if (threads.length === 0) { Logger.log("No emails found with the 'SaveToDrive' label."); } for (var i = 0; i < threads.length; i++) { var messages = threads[i].getMessages(); for (var j = 0; j < messages.length; j++) { var attachments = messages[j].getAttachments(); for (var k = 0; k < attachments.length; k++) { folder.createFile(attachments[k]); } } threads[i].removeLabel(label); // optional, prevents re-processing }}