I would like to get the user email to check his credits in the service. Preferably without any SSO magic like we can in Google Docs addons https://developers.google.com/apps-script/reference/base/user
Asked
Active
Viewed 2,959 times
1 Answers
4
userProfile
object contains the member emailAddress
which return String of the user's SMTP email address. This member available from 1.0 level of API and example of usage may looks like ...
// Example: allieb@contoso.com
Office.initialize = function (reason) {
$(function () {
console.log(Office.context.mailbox.userProfile.emailAddress);
}
}
Please note: Current Office.js API for Word/Excel/PowerPoint doesn't offer functionality to retrieve user name/e-mail address.

Slava Ivanov
- 6,666
- 2
- 23
- 34
-
1Unfortunately no luck "Uncaught TypeError: Cannot read property 'userProfile' of undefined" – giorgio79 Mar 13 '18 at 14:14
-
Your code must be inside initialization function of the Office. More is over here: [Understanding the JavaScript API for Office](https://learn.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office). I'll change the example for you in a sec. – Slava Ivanov Mar 13 '18 at 14:23
-
2Much appreciated. Looks like this object is only available for Outlook addins. Unfortunately, no user id, or email or any identifier is available for the Word addin https://learn.microsoft.com/en-us/office/dev/add-ins/develop/understanding-the-javascript-api-for-office#mailbox-object – giorgio79 Mar 13 '18 at 14:33
-
2Looks like we must do the SSO magic to authenticate https://learn.microsoft.com/en-us/office/dev/add-ins/develop/sso-in-office-add-ins – giorgio79 Mar 13 '18 at 14:35
-
1Sorry, my mistake, I thought you are talking about Outlook when referring to e-mail addresses. For any other Office products this info is not available: [How to get username, email address, filename from task pane app](https://stackoverflow.com/questions/36261336/how-to-get-username-email-address-filename-from-task-pane-app). I'll correct the answer once more. – Slava Ivanov Mar 13 '18 at 14:38
-
1@J.Lavoie I am sorry, I don't have insights. – Slava Ivanov Jun 04 '19 at 19:54
-
@SlavaIvanov this code results in an email address that looks like this: outlook_6************D@outlook.com...is there any way to get the users actual email address and not the SMTP address? I would expect something like foo@bar.com to come back, not that unique outlook value. – rocketlobster Jul 07 '19 at 15:54
-
@rocketlobster Per documentation the `emailAddress` is return SMTP e-mail address. I am not aware of the Office js API function which return aliases. You may want to look at REST API `GET: https://outlook.office.com/api/v2.0/me` request, if it returns something you would want, but I believe the better way is just to create your own question and somebody may help you better. Best regards. – Slava Ivanov Jul 08 '19 at 13:51