How to auto delete old mail in gmail

Gmail allows you to automatically delete old emails using filters. Here's how to do it:

Method 1: Using Gmail's built-in feature

  1. Log in to your Gmail account.
  2. Click on the gear icon () in the upper right corner and select "See all settings."
  3. Go to the "Filters and Blocked Addresses" tab.
  4. Click on "Create a new filter."
  5. In the "From" field, enter older_than:<number>days (e.g., older_than:30days to delete emails older than 30 days).
  6. Click "Create filter."
  7. In the "Apply the label" dropdown menu, select "Delete it."
  8. Click "Create."

Method 2: Using a third-party add-on

  1. Install the "Snooze" add-on from the Google Workspace Marketplace.
  2. Log in to your Gmail account.
  3. Click on the Snooze icon () in the upper right corner.
  4. Click on "Settings" and then "Filters."
  5. Click on "New Filter."
  6. In the "From" field, enter older_than:<number>days (e.g., older_than:30days to delete emails older than 30 days).
  7. Click "Create filter."
  8. In the "Apply the label" dropdown menu, select "Delete it."
  9. Click "Create."

Method 3: Using a script

  1. Enable the "Script Editor" in your Gmail account by going to the gear icon () > "See all settings" > "Labs" and enabling "Script Editor."

  2. Create a new script by clicking on the "Create" button.

  3. In the script editor, paste the following code:

    function deleteOldEmails() {
    var threads = GmailApp.searchThreads('older_than:<number>days');
    for (var i = 0; i < threads.length; i++) {
     threads[i].delete();
    }
    }

    Replace <number> with the number of days you want to delete emails older than.

  4. Save the script by clicking on the "Save" button.

  5. Set up a trigger to run the script at the desired interval (e.g., daily) by clicking on the "Triggers" tab and creating a new trigger.

Note: Before deleting old emails, make sure to backup your important emails or use a third-party add-on like "Snooze" to move them to a separate label instead of deleting them.