Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

What is the best way to fetch the user profile from an e-mail address?

I have a site collection in which I have to get a hold of a MOSS UserProfile object and I only have the users e-mail address. The user is not present in the current site coll user collection, ie I cannot use the SPUtility method. NOTE: the user may not be present in the current site collection.

Only option is to use MOSS search as I can see it, but are there any alternatives?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

Will it be safe to assume that the users email address is stored in the AD? In that case you might use DirectorySearcher to query for a user

share|improve this answer
    
That's another option, have to compare performance for SP Search vs AD Search. –  Wictor Wilen MCA MCM MVP Nov 13 '09 at 11:51
    
Hi Wictor, any preliminary findings that you like to share? I have used DirectorySearcher on previous projects and I found the performance acceptable. –  Kasper Bo Larsen Nov 15 '09 at 13:19
    
We could make the client to change some functionality and could skip this step, but anyways this was the solution I was going to use otherwise (combined with some in-memory caching) –  Wictor Wilen MCA MCM MVP Nov 15 '09 at 21:56
    
i burned my fingers a couple of times on the DirectorySearcher. Problem i saw was that FindOne would ramdomly choose not to return anything even though data existed. –  Anders Rask Nov 16 '09 at 0:00
add comment

You can use the GetUserLoginFromEmail operation of the UserGroup Web Service to get the domain\username login information from the email. Then use GetUserProfileByName to grab the profile, as Lori mentions above.

Take a look at my jQuery Library for SharePoint Web Services if you'd like to do all this client side with jQuery.

M.

share|improve this answer
    
Nice one Marc. Presumably it needs to be called on a site collection that contains the user we are looking for? I hope Wictor has that information :) –  Jaap Vossers Nov 12 '09 at 17:21
    
Yes, the user has to be in the Site Collection. If they weren't, where would we be looking? Using the Web Services, you can look in any other Site Collection, of course, as long as you are authenticated. –  Marc D Anderson Nov 12 '09 at 17:28
    
Marc, that is the problem, the user is not in the site coll. I do not want to have all 80.000+ users in everyones My Site! And that's why I'm asking... –  Wictor Wilen MCA MCM MVP Nov 12 '09 at 17:43
    
So where are they? If they exist in another Site Collection, you can call the Web Services there. –  Marc D Anderson Nov 12 '09 at 19:30
    
All users exists in the profile database, and the profile database requires the username (or id) to fetch the profile. Worst case scenarios is that I have to iterate the profile database or try a number of site colls until I find the user. So I lean towards the Search method; use people search and search for the email address. Just hoped someone made a GetUserLoginFromEmail for the UserProfileManager... –  Wictor Wilen MCA MCM MVP Nov 12 '09 at 19:42
show 2 more comments

I dont' know if this is possible in your situation. It would really depend on the structure of the email address. If the email address is the username@domain.com you could parse out the username and use that to use the GetUserProfileByName operation of the UserProfileService web service. Even if that is not the format of the email, you may be able to manipulate the email with some javascript or something to get the username. Remember, you will have to use domain\username to call the user profile from the web service. I'm really not a dev, but this web service is something I use all the time.

Lori

share|improve this answer
    
Unfortunatley the username and e-mail does not even resemble each other :-( –  Wictor Wilen MCA MCM MVP Nov 12 '09 at 17:43
add comment

How about creating your own hashtable that maps usernames to emailaddresses, for example on a custom SPPersistedObject, which gets populated by a timerjob that does iterate trough all mysites?

share|improve this answer
    
To get it performant some cache should be needed, so I don't have to hit the AD or SP Search everytime. –  Wictor Wilen MCA MCM MVP Nov 13 '09 at 11:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.