3
votes

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
any error while calling this from spreadsheet?Nitin Dhomse
before calling this function from button click call it manually from dropdownNitin Dhomse
Nope, no errors, just nothing happens. Call it from a dropdown? Do you mean a custom menu? If I try to add a .ui then I get an error saying that .ui can't be called in this instance.James D
What @NitinDhomse is trying to say is, execute the email sending function manually from the Code.gs.Parag Jadhav
@JamesDonnellan is there any particular reason to run the script from your account?Parag Jadhav

1 Answers

2
votes

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:

enter image description here