Search code examples
countgmailgmail-api

How can I analyze my Gmail History for Most Emailed?


Besides this nifty tool i found : https://immersion.media.mit.edu/

Is there any other tool/google script that can simply tell me a list of the top most emails sent ( ideally with date filters and in a spreadsheet format ) ?

the issue with Immersion is it wont show me a Subject line.


Solution

  • I don't know of any tools for your specific problem, but you could write a script and connect to a google spreadsheet on google drive - Google's tutorial (i.e. make your own tool). This would be particularly useful if you want the results formatted as a spreadsheet.

    Once you've figured out how to write a google script, you can use the global variable GmailApp to query your emails and iterate through the results like so:

    function myFunction() {
      var maxResults = 200; // the number of results the seach gives at a time
      var query = "from: Joe"; // the same as a search query you would type into the gmail ui
      var count = 0; // the index of the last searched email
      var threads;
    
      do {
        threads = GmailApp.search(query, count, maxResults);
    
        /* you can manipulate threads here */
    
        count += threads.length;
      }
      while (threads.length === maxResults); // when the results are no longer full you've counted them all
    }
    

    Or if the total number of results isn't expected to be very large, you can just directly call: GmailApp.search(query);

    Depend heavily on the query to tailor your results because the script can get very slow if you need to make a lot of calls to thread.getMessages() to check stuff. Google's search query can do it all much faster.

    Here's how you can make a gmail query based on the date.