Google Sheets web app to run script as owner

◇◆丶佛笑我妖孽 提交于 2019-12-11 07:39:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!