title: How to use Google App Scripts to retrieve Gmail emails in a customised way?
body: <p>Here's a neat javascript code I wrote to get all emails from my Gmail and put the list of sender name in a google spreadsheet.</p>
  
  <pre><code>function doGet()
  {
    var myspreadsheet = SpreadsheetApp.openById("0Atg1TJnn4dFdGbjNGSrMGJRdGc");
    var mysheet = myspreadsheet.getSheets()[0];
    var threads = GmailApp.getInboxThreads();
    var messages = GmailApp.getMessagesForThreads(threads); 
    var froms = [];
  
    for(var i = 0; i &lt; threads.length; i++)
    {
      froms.push([messages[i][0].getFrom(),i]);
    }
  
    mysheet.getRange(1,1,threads.length,2).setValues(froms);
  
  }
  </code></pre>
  
  <p>It works great but there're 2 issues</p>
  
  <ol>
  <li><p>The <a href="https://developers.google.com/apps-script/class_gmailapp#getInboxThreads" rel="nofollow">GetInboxThreads</a> method only gets the first 500 emails whatever you try. The question is does someone know how to get more than 500 ? How about get the last 500 rather than the first 500 emails ?</p></li>
  <li><p>It's a bit slow, although I put loads of effort to make it efficient, can someone suggest how to retrieve the sender name from the emails and put that list of sender names on a spreadsheet in a quick way ?</p></li>
  </ol>