Getting user's AD account

  • Thread starter Thread starter khai
  • Start date Start date
NameSpace.CurrentUser.AddressEntry returns an AddressEntry object. Use
AddressEntry.Name or AddressEntry.Address to get whichever you want. Address
will be in EX form as an EX DN.
 
Outlook2007 only:
Application.Session.CurrentUser.AddressEntry.GetExchangeUser.
You can then use ExchangeUser.Alias property.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
This works for getting the sender's account. But how can I get the
recipient's AD account?

I have also noticed that in the Outlook address book, some of the user's
email address (i.e. ... /cn=...) is not the same as the alias field. I need
to get the user's AD account (i.e. login information) as I would like to
programmatically assign the ACL based on the recipients list.
 
Is there a workaround for Outlook 2003?

Dmitry Streblechenko said:
Outlook2007 only:
Application.Session.CurrentUser.AddressEntry.GetExchangeUser.
You can then use ExchangeUser.Alias property.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
As Ken mentioned, you can either
1. run an AD query,
2. use Extended MAPI (C++ or Delphi) to read the PR_ACCOUNT property from
the coresponding IMailUser object or
3. <plug> use Redemption - it exposes RDOAddressEntry.Alias property and
workds in all versions of Outlook </plug>.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
 
Are you referring to the following:
'*** Get the current User
Dim oWNetwork
Set oWNetwork = CreateObject("WScript.Network")
Set oRootDSE = GetObject("LDAP://RootDSE")
Set oMyDomain = GetObject("LDAP://" & _
oRootDSE.Get("defaultNamingContext"))
Set cnn = CreateObject("ADODB.Connection")
cnn.provider = "adsDSOObject"
cnn.Open oMyDomain.ADSPath
Set rst = CreateObject("ADODB.Recordset")

'*** UserPath in AD
StrSQL = "SELECT adspath " &_
"FROM '" & oMyDomain.ADSPath & "'" & _
"WHERE SAMAccountName ='" & oWNetwork.UserName & "'"
rst.Open StrSQL, cnn
ADUserPath = rst.Fields("adspath")
Set ADAccount = GetObject(ADUserPath)

'*** Users Data
Item.UserProperties.Find("UserName") = ADAccount.FullName
Item.UserProperties.Find("UserInitials") = ADAccount.initials
Item.UserProperties.Find("userPhone") = ADAccount.telephoneNumber

Is there a C# version?
 
Yes, that's the sort of LDAP query you'd need. Google is your friend for
trying to find a C# example of an LDAP query.
 
I found a workaround:

##############################
Domain dmn = Domain.GetCurrentDomain();
DirectoryContext ctx = new DirectoryContext(DirectoryContextType.Domain,
dmn.Name);
DomainControllerCollection dcc = DomainController.FindAll(ctx);

foreach(DomainController dc in dcc)
{
DirectorySearcher ds;
using (ds = dc.GetDirectorySearcher())
{
ds.Filter = String.Format("(email=" + emailAcc + ")");
}
SearchResult sr = ds.FindOne();
ResultPropertyCollection rpc = sr.Properties;
foreach(string prop in rpc.PropertyNames)
{
foreach(Object obj in rpc[prop])
{
if (prop.ToLower() == "mailnickname")
{
userName = obj.ToString();
}
}
}
}
....
#################################

This works on my development environment. However when I port this over to
my production environment, I receive the following error:

"The server is not operational"

@ line 'SearchResult sr = ds.FindOne();'

I tried with FindAll(), but receive the same error.

Is there an explanation or solution for this?
 
I don't know. I don't do a lot with LDAP queries. You might be best off
posting this in one of the Exchange development groups where they use LDAP
more often, such as microsoft.public.exchange.applications.
 
Back
Top