Apps Script to get all email address(es) of INBOX emails (all Labels)

This utility is intended to fetch the email ids of all received emails. This Google Apps Script fetches all INBOX mail ids irrespective of labels.

https://script.google.com/macros/s/AKfycbyHloRMiqIQeiAD8XhcpexGLWYZ5K7jWkXqWqYJfTa4tfhu65Kj/exec?start=1&end=50


You will have to specify start end parameter values. The above script URL fetches first 50 mail ids. Since the script has to access your Gmail you will be asked to authorize it before execution. You may encounter some restrictions as google will not allow you to run too many requests. 

Kindly refer the quota limits addressed here

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
function doGet(e) {
  var result = "";
  var from = [];
  
  if(typeof e.parameter.start=='undefined' || typeof e.parameter.end=='undefined')
    return ContentService.createTextOutput("Invalid arguments...Please visit the below link to know its usage!\nhttp://cybernol.blogspot.in/2016/03/app-script-to-get-all-email-ids-of.html");
  
  var threads = GmailApp.getInboxThreads(e.parameter.start,e.parameter.end);
  result="To know the syntax or how to use please visit the link\nPlease visit the below link to know its usage!\nhttp://cybernol.blogspot.in/2016/03/app-script-to-get-all-email-ids-of.html\n\n----------------Displaying from "+ e.parameter.start +" to "+ e.parameter.end + " of ("+threads.length+" e-mails) ------------------------\n";
  
 for (var i = 0; i < threads.length; i++)
    from[i]=threads[i].getMessages()[0].getFrom();
  
  return ContentService.createTextOutput(result + from.toString().replace(/,/g, '\n'));
 }

Comments