Runs: Every night

Clear out old promotional emails automatically

Sales and newsletter emails older than a month go to the bin on their own, so your inbox and storage stay tidy without you deleting anything.

Promotional email is harmless one at a time and a mess by the thousand. Gmail can’t delete mail by age with a normal filter, but a short script can, and it only takes ten minutes to set up once.

  1. Preview what will be cleared

    In Gmail's search box, paste:

    category:promotions older_than:30d -is:starred -is:important
    

    These are the emails the bot will move to the bin. Starred and important ones are skipped. If something you want to keep shows up, star it.

  2. Start a new script

    Go to script.google.com, click New project and name it Inbox cleanup.

  3. Paste the script

    Replace everything in the editor with this. Change 30 if you want to keep promotions for longer:

    const DAYS = 30;
    
    function cleanPromotions() {
      const query = 'category:promotions older_than:' + DAYS + 'd -is:starred -is:important';
      for (let round = 0; round < 10; round++) {
        const threads = GmailApp.search(query, 0, 100);
        if (threads.length === 0) return;
        GmailApp.moveThreadsToTrash(threads);
      }
    }
    
  4. Run it once and allow access

    Click Run and allow access to Gmail. Each run clears up to 1,000 conversations, so a big backlog may take a few nights.

  5. Run it every night

    Open Triggers, click Add trigger, choose cleanPromotions, Time-driven, Day timer, Midnight to 1 am, and save.

Things that trip people up

  • The Promotions tab only exists if Gmail's inbox categories are on. Without it, the search finds nothing.
  • Emails stay in the bin for 30 days before Gmail deletes them for good, so you can still rescue one.