How to bulk delete emails from Gmail
2 points by atum47 15 hours ago | 3 comments
Just saw a post about a service that provides, among other things, bulk email deletion on Gmail; but you have to give them access to your account (Yeah, that's a NO for me dog). Coincidentally, not so long ago I was talking to ChatGPT about how to do just that (I reckon that ChatGPT has read every manual and API documentation in existence). Anyways, here's the tutorial that it gave me and that I have tested.

Steps:

1. Open Google Apps Script (drive.google.com > new > more > Google Apps Scripts)

2. Click create scripts.

3. Write the Script:

    function deleteOldEmails() {
        var threads = GmailApp.search('older_than:1y');
        for (var i = 0; i < threads.length; i++) {
            threads[i].moveToTrash();
        }
    }
This example deletes emails older than one year (older_than:1y). You can modify the search query for different criteria (e.g., label:unread, from:[email protected], before:YYYY/MM/DD).

4. Save the Script.

5. Run the Script:

Click the play icon to run the script. It will ask for permissions the first time.

This method allows you to automate email management using custom queries.

If you want to test the search string - GmailApp.search(...) - to be sure you are deleting the right emails, you can use the filter on the search bar on Gmail.

  • m9a4r3a3n 14 hours ago |
    Thanks, i was trying to download some of emails lately. After slamming some keys i found takeouts manages downloading data throughout google services. But this feels more interesting, i’ll see if i could download them with this!
    • atum47 14 hours ago |
      Anytime
    • atum47 14 hours ago |
      By the way, I did that years ago by setting up my Gmail account on Thunderbird. Got all my emails, stored the important ones in a zip file.