Info:
I have a google doc with a list of emails, separated by newlines like such:
Email1@gmail.com
Email2@gmail.com
Email3@gmail.com
...
Ideally, I would like to, from the gmail that owns the doc, be able to run a script that copies all of the emails in the doc directly into a gmail recipients tab when I want to compose an email to that list of people.
I am aware there are probably other ways to do a similar thing, for example, printing out the contents to a terminal or something of the like. I would prefer to use the Google Docs API, but am open to ways that are outside of that. Edit: Copying the text to a clipboard would also be acceptable, I just have no idea how to do that.
Any help would be greatly appreciated! Thanks.
Also, if I've left out key information please let me know!
Current Code in Google Apps Script (Google Docs API):
function grabText() {
const documentID = 'mydocumentid';
return DocumentApp.openById(documentID).getBody().getText().split(/\n/).join(',');
}
Try this:
Paste the script into the script editor of the document you wish it to access. It will return a string of comma separated emails that you can paste into your email script.
I added the Logger.log() so that you can see the recipients for testing.
function getEmails() {
const recipients = DocumentApp.getActiveDocument().getBody().getText().split(/\n/).join(',');
Logger.log(recipients)
return recipients
}