User().Email not returning correct email of the user in Power Apps canvas apps

I am back with another blog on Power Apps and this time I will discuss about a very simple requirement. The requirement is to get the email address of a user in Power Apps canvas apps.

It’s so common a requirement that anyone developing Canvas apps at basic level is aware of how to do it. And the most common formula used to get the user email is – User().Email

Why not? After the User() function is something which catches our eye the first time we develop canvas apps. And in nearly most of the scenarios, the code shall work fine to return the email of the user except in certain cases where your User principal name and your email is different in Azure AD.

Not understanding? Let’s take an example.

Below is the set up of a user named John Cena (big fan of him in WWE)

Observe the user name. It is – john101@mb910cw.onmicrosoft.com

For the same user, the email is different in Azure AD.

And in cases like this, the User().Email function will fail to return the value of Email field. And before you start blaming Microsoft, here is the documentation of the User() function.

Not to blame the newbies to Canvas apps. The function is too good to go wrong.

But what is the way to get the correct email address field value of the user? For that you need to rely on the Office 365 Users.

Below is the code to get the email address.

Office365Users.MyProfile().Mail

Hope this helped!

You might also like the below posts.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading