Web Applications Stack Exchange is a question and answer site for power users of web applications. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I want to send a newsletter using mailchimp to everyone I've had an email conversation with over the past year. What is the best way to export their email addresses? I only want people I've gone back and forth with (I've sent them at least one email and they've sent me at least one email).

I'm on a mac and can use apple mail if that helps.

share|improve this question

marked as duplicate by OnenOnlyWalter, ChrisF Aug 18 '13 at 18:47

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.

Related: Get e-mail addresses from Gmail messages received – Al E. Aug 14 '13 at 17:56
You might also have a look at a third-party Gmail management solution, like Mailstrom. – Al E. Aug 14 '13 at 17:56
@AlEverett None of these include a way to only get contacts by time. I don't want to spam people I haven't talked to in 2 years. – Alex Aug 14 '13 at 18:22

Use this script to efficiently retrieve the addresses you want (given the time span) and remove duplicates:


function getEmails() { 
  // http://stackoverflow.com/a/12029701/1536038  
  // get all messages      
  var eMails = GmailApp.getMessagesForThreads(
    GmailApp.search('after:2012/1/14 before:2013/8/15'))
      .reduce(function(a, b) {return a.concat(b);})
      .map(function(eMails) {
    return eMails.getFrom() 

  // sort and filter for unique entries  
  var aEmails = eMails.sort().filter(function(el,j,a)
    {if(j==a.indexOf(el))return 1;return 0});  

  // create 2D-array
  var aUnique = new Array();  
  for(var k in aEmails) {

  // add data to sheet
  SpreadsheetApp.getActiveSheet().getRange(1, 1, aUnique.length, 1)
share|improve this answer
This is definitely better than what I had. However, the end result is missing a significant number of email addresses that I know should be on the list. Perhaps you're hitting an API limit somewhere? – Alex Aug 14 '13 at 21:52
This script will read approx. 3000 items across your mailbox in 5 minutes. Beyond that it will stop. Try adding the extra search parameter in the duplicate post: "label:" + labels[i].getName() + "after:2012/1/14 before:2013/8/15". This way it's confined to the label. – Jacob Jan Tuinstra Aug 14 '13 at 22:10
@Alex forgot to hail you... – Jacob Jan Tuinstra Aug 14 '13 at 22:10

I think I wrote a script to do this in Google Apps Script

function processInbox() {
  // get all threads within the time range
  var threads =   GmailApp.search('after:2012/1/14 before:2014/8/15');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // find all threads with more than one message     
  for (var i = 0; i < threads.length; i++) {
    var messages = threads[i].getMessages();
    // get all threads longer than 1
    if (messages.length > 1)
      // get all participants in those threads and add them to a spreadsheet
      for (var j = 0; j< messages.length; j++){
share|improve this answer
Your script has some major flaws. First, the number of API calls is huge. The script, in my gmail, didn't even complete. Second, your code didn't take into account the duplicates. My script runs in 21 sec., yours didn't complete in the first place !! – Jacob Jan Tuinstra Aug 14 '13 at 20:05

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