How To Have Gmail Delete Old Emails

Handling your emails can prove to be a difficult task, particularly when confronted with a large number of spam or advertisement messages. One approach to maintaining a tidy inbox is by enabling Gmail to automatically remove old emails. In this article, we will provide you with step-by-step instructions on how to achieve this.

Create a Filter

The first step in getting Gmail to delete old emails is to create a filter. This filter can be based on several factors including sender, subject, size, and date. For our purposes, we’ll create a filter that targets emails older than 30 days.

To create a filter in Gmail:

  1. Click the down arrow in your Gmail’s search box, which will open the advanced search box.
  2. In the “Has the words” field, input “older_than:30d”. This will target all emails older than 30 days.
  3. Click the “Create filter” button.

Configure the Filter to Delete Old Emails

After creating your filter, the next step is to configure it to delete the old emails it targets. To do this:

  1. Check the box next to “Delete it”.
  2. Click the “Create filter” button to finalize the process.

Warning: Be cautious when using this method, as it will permanently delete all emails older than 30 days. Always verify the filters you have set up to avoid deleting important emails.

Automating the Process

Unfortunately, Gmail does not automatically apply these filters to incoming emails. However, you can bypass this limitation by using a script that runs the filter automatically at specified intervals.

To enable this, we’ll be using Google Apps Script, a scripting platform developed by Google for light-weight application development in the G Suite platform.

Here’s the script for running the filter for every incoming email:

function autoDelete() {
  var threads ='older_than:30d');
  for (var i = 0; i < threads.length; i++) {

After creating this script:

  1. In the Google Apps Script interface, click on “Current project’s triggers” which is the clock-like icon on the left side of the page.
  2. Click on “+ Add Trigger”.
  3. Choose “autoDelete” from the “Choose which function to run” dropdown.
  4. Choose “Time-driven” from the “Choose which deployment should run” dropdown.
  5. Configure the frequency at which the trigger should run. For instance, you can set it to run the function “Every day”.
  6. Click “Save”

Note: You’ll need to authorize the script to run on your Gmail account. Make sure to review the permissions and ensure you trust the script before doing so.

By following the steps above, you can automate the process of deleting old emails, keeping your inbox neat and tidy.