Second Life of a Hungarian SharePoint Geek

October 10, 2012

Resolving SharePoint users based on their e-mail address

Filed under: Incoming email, SP 2010 — Tags: , — Peter Holpar @ 20:22

If you send a meeting request to a SharePoint calendar, the default SharePoint infrastructure does not resolve the participants’ mail addresses to meeting attendees (see Issue 2 in my former post).

Last week I was working on a solution for this issue, one of my tasks was to find out the user based on the e-mail address.

Trying to solve this problem we might apply a few alternative approaches, but most of them have a significant drawback:

  • Use an SPUserCollection instance, like the AllUsers property of the SPWeb object, then call its GetByEmail method. Unfortunately, if there is no matching user in the collection, this method throws an exception, and most importantly, if the user has access to the site through a group membership (that is a rather common case), it simply does not work.
  • Use the user profile service to look up the user. Despite being not the best performing way (especially if there is a large number of user profiles), this approach might at least work. To make things a bit faster, instead of iterating through all profiles we can try to crawl the user profile properties and use Search API for the lookup. However, we need a solution that is accessible in the case of SharePoint Foundation as well, so it was a dead-end in our case.
  • Since the People Picker in SharePoint already has a similar functionality, I’ve analyzed its implementation using Reflector, and then came up with the following – quite simple and fast – solution:

SPPrincipalInfo pi = SPUtility.ResolveWindowsPrincipal(site.WebApplication, mailAddress, SPPrincipalType.User, true);
if ((pi != null) && (!string.IsNullOrEmpty(pi.LoginName)))
    SPUser user = web.EnsureUser(pi.LoginName);
    Console.WriteLine("User LoginName: {0}; Name: {1}", user.LoginName, user.Name);

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: