0

This question already has an answer here:

I have 5000 mail messages in my Gmail inbox, and every message has an email address in it.

I need those addresses in one place, so, is there any way of doing that automatically or do I need to do it one by one?

marked as duplicate by ale gmail Jan 18 '17 at 13:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Hi user144601. I tried to interpret what you were trying to say, but do you mean the senders or do the bodies of the emails include the addresses? – jonsca Jan 18 '17 at 1:58
4

Using google apps script attached to a spreadsheet you can export all senders using the following:

function sender_list() {
  var inbox_threads = GmailApp.getInboxThreads();

  var sender_array = [];

  for (var i = 0; i < inbox_threads.length; i++) {
    var message = inbox_threads[i].getMessages();
    for (var x = 0; x < message.length; x++) {
      var sender = message[x].getFrom();
      sender_array.push([sender]);      
    }
  }
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName('sheet1');
  sheet.clear();
  sheet.appendRow(['Email Address']);
  sender_array.sort();
  sheet.getRange(sheet.getLastRow()+1, 1, sender_array.length,1).setValues(sender_array);
}
  1. Open a new spreadsheet, click on tools --> script editor (opens new tab).
  2. Copy and paste the code above into your code editor.
  3. Save
  4. Click Run --> sender_list
  5. You will have a notification asking for authorization to access email and spreadsheets.
  6. After it runs you will have all e-mail addresses which have sent messages to your inbox.

This imports every instance, so duplicates will appear if they exist. If you are looking to import a list without duplicates you can use the code below.

function sender_list() {
  var inbox_threads = GmailApp.getInboxThreads();

  var sender_array = new Array();

  for (var i = 0; i < inbox_threads.length; i++) {
    var message = inbox_threads[i].getMessages();
    for (var x = 0; x < message.length; x++) {
      var sender = message[x].getFrom();
      if(sender_array.indexOf(sender) == -1){
        sender_array.push(sender); 
      }
    }
  }


  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheetByName('sheet1');
  sheet.clear();
  sheet.appendRow(['Email Address']);
  sender_array.sort();
  var row = sheet.getLastRow() + 1;
  for (var y = 0; y < sender_array.length; y++) {
    sheet.getRange(row, 1).setValue(sender_array[y]);
    row++;
  }
}
  • It works, I have to change the name "sheet1" because the app was in french and keep the name of the function to be "myFunction" to avoid errors. – bormat Jul 27 at 11:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.