How to Sort Gmail Messages by Size
What do you do when your Gmail account storage is nearly full? You can either purchase additional storage space from Google - they charge $5 per year for 20 GB - or a cheaper alternative would be that you scan your Gmail mailbox for messages that contain large file attachments and delete (or forward) all the bigger messages and recover precious space.
The problem is how do you find these bulky messages in your mailbox when Gmail doesn’t offer an option to sort and filter messages by size?
What we use is a simple Google Sheet that connects to Gmail, computes the size of individual messages and lists the bulky ones (size > 1MB) in the same Sheet. Here’s how you can get started:
- Create a copy of the Gmail Sort Google Sheet in your Google Drive.
- Click Scan Mailbox under the Gmail menu and authorize to let the script access your Gmail Inbox. It is an open-source Gmail Script that runs in your own Drive.
Sit back and relax as the script will pull the message list in the sheet. If the process stops for some reason, click Scan Mailbox again and the script will resume scanning from where it left off.
Once the sheet has a list of all the bulky message, you can sort the sheet by the Size column to find the big ones. Or use the Filter option (the Funnel icon) to find messages that are within a particular range (5 MB < size < 10 MB). Click the “View” link to open the corresponding message in Gmail, bulk auto-forward the big email to another email address or use the Save Emails add-on to download the big emails and attachments to your Google Drive.
Troubleshooting tips: If you get an error that says “Service invoked too many times for one day” or “Exceeded maximum execution time”, you may want to wait for some time before re-running the program. These are Google Apps Script limits to prevent abuse.
If your Gmail mailbox is large, you can also set up a time-driven trigger to let the script run automatically without manual intervention. In this case, you can even close the browser tab and the script will run in the background. Here’s how:
- While the Google sheet is open, go to Tools -> Script Editor. On the next screen, choose Resources -> Current Script Triggers.
- Click “Add a New Trigger,” change the Event from “Spreadsheet” to “Time Driven” and set a minutes timer that triggers every 10 minutes.
- Save the trigger, authorize the script if it requires and close the sheet.
Google Developer Expert, Google Cloud Champion
Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India.