TASK:
- I want to send an email to a receiver using the user's email ID who has installed the google form addon
- I want to trigger this function from my backend after a certain condition is met.
PROBLEM:
- I cannot call this function from my backend unless I execute the script as myself. Which I don't want
How to achieve this?
Here is what I have tried. The issue is that when I deploy as img below and when I trigger doPost function from backend it does not run as it does not know from which users context script has to be run
Here is the code
function triggerdoPost() {
var URL='https://script.google.com/macros/s/AKfycbzM97wKyc0en6UrqXnVZuR9KLCf-UZAEpzfzZogbYApD9KChnnM/exec';
var payload = {payloadToSend : '[email protected]'};
var method = 'post'
var response = UrlFetchApp.fetch(url, {method : method, payload: payload, headers: headers}).getContentText();
Logger.log(response);
return;
}
Been stuck for 3 days.
Any guidance is appreciated
TIA
CodePudding user response:
So after struggling for 4 days I was able to send email and write to spreadsheet with users OAuth token by directly interacting with Sheets API and Gmail API instead of doing it through ScriptApp doPost method