Info:
I have a google doc with a list of emails, separated by newlines like such:
[email protected]
[email protected]
[email protected]
...
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(',');
}
CodePudding user response:
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
}
CodePudding user response:
Does it need to by python or JavaScript? What I would do, is run an AutoHotKey script like this:
Sleep, 3000
Send, [email protected] [email protected] [email protected]
In order to get these emails in a list this way, you can copy-paste the google docs with all the emails into VScode (or another text editor with support for Replace All), select a newline character (by dragging your most from the start of line 2 to the end of line 1, for example), and replacing all newlines with a space. The sleep, 3000 is there so that you have 3 seconds between when you run the AHK script and you move your mouse over to the mail recipient text box.