I recommend you to run a server script that would query the datasource that has the emails. The script will look something like this:
function getEmails(){ var query = app.models.<yourmodel>.newQuery(); var results = query.run(); var allEmails = []; if(results.length > 0){ for(var i = 0; i < results.length; i++){ var uniqueEmail = results[i].<emailfieldname>; allEmails.push(uniqueEmail); } } return allEmails.join(); }
Then add a script to the button widget "onclick" event that will run the server script and manipulate the returned data. Something similar to this:
function poulateToField(response){ <widget path>.text/value = response; } google.script.run.withSuccessHandler(poulateToField).getEmails();
The above widget path would be the path to the "To:" widget, which can be a text box, text area, etc. In my case, I used a text area and the path was this "widget.parent.descendants.TextArea1.value"
I hope this helps. If you have more questions, just let me know! :)
P.D. Please don't forget to review the official documentation for a better and more detailed explanation.