Home > OS >  Apps Script: Use alias selected from dropdown list instead of alias of currently logged user
Apps Script: Use alias selected from dropdown list instead of alias of currently logged user

Time:01-06

We have a sidebar containing a simple html form to book appointments. It contains a dropdown list filled with email-addresses coming from a Google sheet. Anybody who wants to book an appointment must choose an email-address from that dropdown list. The selected email-address will then be used as the sender. Example: If I select [email protected] from the dropdown list, then the sender for the booking confirmation will be [email protected].

And as you can imagine, [email protected] is actually an alias that´s been created in John Doe´s Gmail-account. The same is true for all other email-addresses in that dropdown. In other words, each email-address in the dropdown list is an alias for a Gmail-account. We get all these aliases with this line of code:

var aliases = GmailApp.getAliases();

Now the problem is that the booking confirmation email will always be sent with the alias of the person currently logged/using the script instead of the email-address selected in the dropdown list. So, my question is: How can we make sure that the email-address selected from the dropdown list is used as the sender instead of the alias of the person currently running the script?

I´d appreciate any help or hint. And if you need more meat on the bones, please let me know.

CodePudding user response:

You literally can't. This would be a massive security issue as any email could be sent by anyone.

The only workaround I can think of would be to deploy a Web App for each user which sends an email on their behalf, and then calling the corresponding Web App URL using UrlFetchApp from the Sheet script, but this is really not something I would recommend. If you do decide to go down this route though, at the very least make sure that the contents of the email are not passed as doGet(e) parameters as it has severe potential for abuse.

  •  Tags:  
  • Related