Based off of @Jacob Jan Tuinstra's@jacob-jan-tuinstra's answer. Made some minor modifications to suit my needs perhaps others would find it useful.
function getEmails() { // set spreadsheet and retrieve labels var query = 'YOUR GMAIL SEARCH QUERY GOES HERE', ss = SpreadsheetApp.getActiveSpreadsheet(), sh = ss.getSheetByName(query) || ss.insertSheet(query, ss.getSheets().length), uniqueEmails = {}, errors = [], // max chunk size chunkSize = 500, currentChunk = 0, threads, messages, i, j, k, msg, tos; sh.clear(); while (currentChunk === 0 || threads.length === chunkSize) { try { // grab threads that match the query one chunk at a time threads = GmailApp.search(query, chunkSize * currentChunk, chunkSize); // grab corresponding messages from the threads messages = GmailApp.getMessagesForThreads(threads); for (i = 0; i < messages.length; i++) { msg = messages[i]; for (j = 0; j < msg.length; j++) { // get the from uniqueEmails[msg[j].getFrom()] = true; // get the reply to uniqueEmails[msg[j].getReplyTo()] = true; // grab from the to field alas well // this has a bug for people with commas in their names // tos = msg[j].getTo().split(','); // for (k = 0; k < tos.length; k++) { // uniqueEmails[tos[k]] = true; // } } } currentChunk += 1; } catch (e) { errors.push(e); } } // create 2D-array var aUnique = []; for (k in uniqueEmails) { aUnique.push([k]); } // add data to corresponding sheet sh.getRange(1, 1, aUnique.length, 1).setValues(aUnique); }