Search code examples
google-apps-scriptgmailread-unread

To manage more than 100 hits with one step


I'm learning Google-App-Script. An I have written a very simply script to manage my emails:

var threads = GmailApp.search('label:Project1 is:unread');
GmailApp.markThreadsRead(threads);

This script works nearly perfect. But when I have more then 100 unread emails in the Label "Porject1" I get the Error-Message that max. 100 Threads are allowed to change.

How can i limit my search command to 99 hits? Or is there another way to manage all hits in one step?


Solution

  • To answer this part of your question:

    How can i limit my searchcommand to 99 hit´s?

    you can use:

    var threads = GmailApp.search('label:Project1 is:unread',0,100);
    

    Also note the max thread results I believe is 500.