M Buck
M Buck

Reputation: 49

Google Apps Script - I am unable to retrieve user's email address when add-on is published

The following code works before I publish the G docs add-on. However the released version obtained via Google Docs Add-on/my_add-on doesn't work.

What concepts am I missing here?

onOpen(){

  var email = Session.getActiveUser().getEmail();

}

Upvotes: 0

Views: 1231

Answers (1)

Robin Gertenbach
Robin Gertenbach

Reputation: 10776

The documentation explicitly states that:

If security policies do not allow access to the user's identity, User.getEmail() returns a blank string. The circumstances in which the email address is available vary: for example, the user's email address is not available in any context that allows a script to run without that user's authorization, like a simple onOpen(e) or onEdit(e) trigger, a custom function in Google Sheets, or a web app deployed to "execute as me" (that is, authorized by the developer instead of the user). However, these restrictions generally do not apply if the developer and the user belong to the same Google Apps for Business domain.

So presumably your script fails to meet those conditions.
You need to run a function that the user has to authorize first in order to get their email.

Upvotes: 1

Related Questions