- Create a new script on http://script.google.com,
- Past the code below,
- Open the menu Publish > Deploy web app..., and copy/paste the script URL(*),
Run the script with the URL (accept the permission questions about Gmail):
https://script.google.com/macros/s/.../dev?label=nameofthelabel
It will directly display the addresses in the browser, without needing a spreadsheet or anything else.
Code:
function doGet(e) { var max = 100; var offset = 0; var searchThreads = []; var addresses = []; while (true) { var threads = GmailApp.search("label:" + e.parameter.label, offset, max); searchThreads = searchThreads.concat(threads); if (threads.length < max) { break; } offset += max; } for (var i = 0; i < searchThreads.length; i++) { var messages = searchThreads[i].getMessages(); for (var j = 0; j < messages.length; j++) { addresses.push(messages[j].getFrom()); } } function onlyUnique(value, index, self) { return self.indexOf(value) === index; } var addr = addresses.filter(onlyUnique).join('\n'); return ContentService.createTextOutput(addr).setMimeType(ContentService.MimeType.TEXT); }
(*) Choose the "latest code" link, ending with /dev , it avoids to redeploy each time you do a tiny modification in code, as detailed here.