Home > Net >  How to send mail using email of user from node in Google Appscript?
How to send mail using email of user from node in Google Appscript?

Time:06-25

TASK:

  1. I want to send an email to a receiver using the user's email ID who has installed the google form addon
  2. I want to trigger this function from my backend after a certain condition is met.

PROBLEM:

  1. 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 enter image description here

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

  • Related