问题
Hi have a simple script that sends an email from a spreadsheet I need to allow the other users of the sheet to call the script but I want the script to be ran as me (the owner) so that the email is sent from my account. I've looked at some similar questions and answers but nothing seems to work.
I've got a button on my sheet calling the doGet function with the following code.
function doGet(e){
UrlFetchApp.fetch('https://script.google.com/a/----.org/macros/s/AKfycbxT------------------------------FK5GbrkI/exec').getResponseCode();
}
If I go to the URL from a browser tab script runs fine but I can't get it to work from clicking the button on my spreadsheet
回答1:
You can create a standalone webapp to handle the emailing. When the user calls the script, a web request is issued from the GAS bound script of the spreadsheet to the published webapp, and in the webapp you can email from your own account (i.e., "Execute the app as: Me"). You can pass arguments as well, for example the email recipient and text could be sent as parameters. Here is a picture for clarity:
来源:https://stackoverflow.com/questions/46397968/google-sheets-web-app-to-run-script-as-owner