Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

SPUser email details

  Asked By: Korey    Date: Nov 22    Category: Sharepoint    Views: 3285

Our SPS installation is configured with Active Directory.
User are added to SPS as AD groups. Email for users is configured in AD.

We are using the SPUser's email method to get the user's email ID.
But this method retrives email ids only for some users. Others have a null value.

I am not sure why this happens. Any ideas?



2 Answers Found

Answer #1    Answered By: Stephon Valentine     Answered On: Nov 22

You should 'refresh' the data in A/D into SPS using
the SPS Profile Database (Site Settings, Manager
profile database). You can also set it to automatic
refresh once in a while.

Then you can use the following code to approach the
UserProfiles (eg to retrieve for the current user) in
your webpart:

// extract the uri from the current site
SPWeb spc = SPControl.GetContextWeb(Context);
Uri uri1 = new Uri(spc.Site.RootWeb.Url);

// initializing GlobalAdmin
SPGlobalAdmin globaladmin = new SPGlobalAdmin();

// getting this Virtual Server
SPVirtualServer virtualserver =

// getting the root url
string sRootUrl = virtualserver.Url.ToString();
tm = new
Microsoft.SharePoint.Portal.Topology.PortalSite ps =
tm.PortalSites[new Uri(sRootUrl)];
PortalContext pc = PortalApplication.GetContext(ps);

//initialize user  profile config manager object
upm = new
UserProfile userProfile =

string sName =
string sEmail = userProfile["WorkEmail"].ToString();
string sID = spc.CurrentUser.ID.ToString();

spc = null;
globaladmin = null;
virtualserver = null;
tm = null;
ps = null;
upm = null;
userProfile = null;

As you can see the email  address is the 'WorkEmail'
property in the UserProfile. If you click on the
'Manage Profile Database' the last option 'View
profile properties' you get an overview of ALL

Answer #2    Answered By: Leif Cardenas     Answered On: Nov 22

At present in our project we are not planning to import data to the SPS server.
So, I was looking at retriving the email  just with the SPUser data which is retrived from the AD.

Didn't find what you were looking for? Find more on SPUser email details Or get search suggestion and latest updates.