How to clean up Gmail inbox [Detailed Guide with Automation]

How to clean up Gmail inbox [Detailed Guide with Automation]

Although Gmail is one very easy-to-use Google application, the intuitive platform can serve as a challenge to figure out when it comes to how to clean up the Gmail inbox effectively. In this blog, we will be teaching users step-by-step directions on how to clean up their Gmail inbox to make their lives easier than ever. 

With so much free space, Gmail users often neglect the importance of inbox management, unsubscribing from newsletters, deletion of old emails, and things they might not be interested in any longer. With 15GB of storage space available for free, and shared across all services of Google, which includes Google Photos and Google Drive, it often occurs late to the user when the account capacity fills up quicker than ever. 

In such cases, the first reaction of most Gmail users is to delete old as well as any useless Gmail emails as soon as possible. However, deleting such a large number of emails in bulk is not as easy as it seems. So, in this article, we will be telling you all about how to clean up your Gmail inbox using the Google Apps Script. It is one of the best ways to save valuable time and clean the clutter using this detailed guide with automation.

When Gmail launched in 2004, it provided 1GB per user storage capacity, much greater than Hotmail as well as Yahoo at the time. As of today, Gmail provides a storage capacity of 15GB for free, along with upgrades to 2 terabytes for $10 each month. 

While Gmail inboxes offer a large amount of space, you should clean up your inbox at least once a year, especially if you have not done it for the past 15 years or so. With such a huge number of emails cluttering your Gmail inbox on a daily basis, the necessity to clean your Gmail inbox every now and then has become more obvious. 

Cleaning up your Gmail inbox will help you organize your life and also help you save money which you might have to pay to Google for that extra storage. 

In this detailed blog, we will be telling you all about how to clean up your emails to not only get rid of any unwanted data but also free up storage. Apart from providing you with some of the best methods to clean up your Gmail inbox, we will also tell you how to do it using automation for a quick progress.

Gmail offers 15 GB quota on free mailboxes and definitely, you will need to clean up your emails to get rid of unwanted data and free up storage.

There are several ways to clean up your Gmail inbox:

  1. Use the search function to find specific emails or types of emails, and then delete them in bulk.
  2. Use Gmail’s “star” system to mark important emails, and then use the search function to find and delete all emails that are not starred.
  3. Create filters to automatically label, archive, delete, or forward incoming emails based on specific criteria, such as sender or subject line.
  4. Use the “Archive” button to remove emails from your inbox without deleting them, so they can be accessed later through the “All Mail” label.
  5. Use the “Trash” button to delete emails that you no longer need.
  6. Unsubscribe from email lists or newsletters that you no longer want to receive.
  7. Organize your emails into folders or labels to keep your inbox more organized and easier to manage.
  8. Regularly review and delete any emails that are no longer relevant or necessary.

How to clean your Gmail Inbox using an automation

Step 1: Find all emails that are bigger in size

At first, let’s find out all emails that are bigger in size.

To get a list of all emails with size more than 5 MB in a Google Sheets document using Google Apps Script, you can follow these steps:

  1. Set up the script: Create a new Google Apps Script project and open the Script Editor.
  2. Authorize the script: In the Script Editor, click the “Run” button and follow the prompts to authorize the script to access your Google account and Gmail.

Here is the full code for getting a list of all emails with size more than 5 MB in a Google Sheets document using Google Apps Script:

// Get the ID of the sheet
var sheetId = "YOUR_SHEET_ID";

// Get a reference to the sheet
var sheet = SpreadsheetApp.openById(sheetId).getSheets()[0];

// Get a list of all emails
var emails = GmailApp.search('size:5m');

// Write the email details to the sheet
for (var i = 0; i < emails.length; i++) {
  var email = emails[i];
  sheet.appendRow([email.getSubject(), email.getFrom(), email.getDate(), email.getId()]);
}

To use this code, you will need to replace “YOUR_SHEET_ID” with the ID of the sheet where you want to store the list of emails. You will also need to authorize the script to access your Google account and Gmail.

This code will get a list of all emails that are larger than 5 MB and write the subject, sender, and date of each email to a row in the sheet. You can modify the code to include additional email details or to use a different search criteria to filter the emails.

Step 2: Delete all emails that match the list of message IDs retrieved in the last script

To delete all emails in Gmail that match a list of message IDs using Google Apps Script, you can use the following steps:

  1. First, you need to retrieve the message IDs from the Google Sheet. You can do this using the getRange and getValues methods of the Spreadsheet class. For example:
// Get the range of cells that contain the message IDs
var range = SpreadsheetApp.getActiveSheet().getRange(4, 4);

// Get the values in the range as a 2D array
var values = range.getValues();
  1. Next, you can retrieve the messages that match the message IDs. You can use the Gmail.Users.Messages.list method for this, which takes a list of message IDs as one of its parameters. This method returns a list of message objects, each of which contains information about a specific message, such as its subject and sender.
  2. Finally, you can loop through the list of message objects and delete each message using the Gmail.Users.Messages.delete method. This method takes a message ID as its parameter, so you can pass the ID of each message to be deleted.

Here is some sample code that demonstrates how to delete all emails in Gmail that match a list of message IDs stored in a Google Sheet:

function deleteEmails() {
  // Get the range of cells that contain the message IDs
  var range = SpreadsheetApp.getActiveSheet().getRange(4, 4);
  
  // Get the values in the range as a 2D array
  var values = range.getValues();
  
  // Flatten the 2D array into a 1D array
  var messageIds = values.flat();
  
  // Retrieve the messages that match the message IDs
  var messages = Gmail.Users.Messages.list('me', { ids: messageIds });
  
  // Loop through the list of messages and delete each one
  for (var i = 0; i < messages.length; i++) {
    var message = messages[i];
    Gmail.Users.Messages.delete('me', message.id);
  }
}

Note that this code assumes that you have authorized the Gmail API and that you have included the Gmail library in your script. You will also need to replace 'me' with the email address of the account you want to delete the messages from.