You are here:   Blog
Register   |  Login

Blog Archive:

* Can be used in order to search for older blogs Entries

Search in blogs

Blog Categories:

* Can be used in order to search for blogs Entries by Categories

Blog Tags:

* Can be used in order to search for blogs by keywords


Awared MVP


Microsoft® Community Contributor 

Microsoft® Community Contributor

 Read this before you use the blog! Maximize

Recent Entries


Written by: ronen ariely
16/08/2019 07:20 RssIcon

I wrote this short script for my personal use. I had over 60k unread massages in specific label and I wanted to mark all the messages before 01/01/2019 as read.

Yes you noticed correct... I have more in other labels! sry but I cannot read all the emails which I get and they just keep coming. If you need me then please contact me on Facebook, linkedin, or Skype.

The problem is that using the GUI Gmail allows us to see maximum 100 emails in a page and manually delete 100 emails at a time might need several hours to end the task. 

Therefore, I choose to use Google script for the task...

But here I ran into another limitation: Google limit the maximum of email returns in the search command "GmailApp.search" to 500. The solution I chose was to use a simple loop and mark 100 emails in each iteration.

function Intialize() {
function Install() {
  var Text2Write = new Date();
  var max = 99;
  var offset = 0;
  while (true) {
    var threads = GmailApp.search("label:MyLabelFilterHere is:unread before:01/01/2017 after:01/01/2016", offset, max);
    if (threads.length < max) {
    ArielyWriteLog("max" + max);
    offset += max;
function ArielyWriteLog(Text2Write) {
  var MyFileName = 'Ronen Ariely Log Spam Emails';
  var files = DriveApp.getFilesByName(MyFileName);
  var file = !files.hasNext() ? DocumentApp.create(MyFileName) : files.next();
  var doc = DocumentApp.openById(file.getId())