jgianni
asked on
Problem retrieving NT account details from CDO
I'm currently writing a Visual Basic component which references CDO for a corporate intranet.
One of the methods of my component will be used to search within the Global Address List for a specific NT user so that I can retrieve their SMTP address & send them emails.
Everything was going fine with writing this component, I can start and log into a MAPI session & gain access to the 'Global Address List' but I am now having problems using one of the MAPI property tags called PR_EMS_AB_ASSOC_NT_ACCOUNT .
I have seen an MSDN article where PR_EMS_AB_ASSOC_NT_ACCOUNT is defined as a
cdo constant - CdoPR_EMS_AB_ASSOC_NT_ACCO UNT with value &H80270102.
Unfortunately, whenever I try & gain access to this property using the 'fields' collection of the AddressEntry object ...
Private Const CdoPR_EMS_AB_ASSOC_NT_ACCO UNT = &H80270102
....
strSID = objAddressEntry.Fields CdoPR_EMS_AB_ASSOC_NT_ACCO UNT).Value
... I get a 'MAPI_E_NOT_FOUND' error. I guess this
is because CDO cannot locate the PR_EMS_AB_ASSOC_NT_ACCOUNT property within
the AddressEntry object despite the documentation within MSDN which suggests otherwise! Please can somebody tell me what I might be doing wrong, or perhaps there is another way to approach this problem?
Thanks
Jon
One of the methods of my component will be used to search within the Global Address List for a specific NT user so that I can retrieve their SMTP address & send them emails.
Everything was going fine with writing this component, I can start and log into a MAPI session & gain access to the 'Global Address List' but I am now having problems using one of the MAPI property tags called PR_EMS_AB_ASSOC_NT_ACCOUNT
I have seen an MSDN article where PR_EMS_AB_ASSOC_NT_ACCOUNT
cdo constant - CdoPR_EMS_AB_ASSOC_NT_ACCO
Unfortunately, whenever I try & gain access to this property using the 'fields' collection of the AddressEntry object ...
Private Const CdoPR_EMS_AB_ASSOC_NT_ACCO
....
strSID = objAddressEntry.Fields CdoPR_EMS_AB_ASSOC_NT_ACCO
... I get a 'MAPI_E_NOT_FOUND' error. I guess this
is because CDO cannot locate the PR_EMS_AB_ASSOC_NT_ACCOUNT
the AddressEntry object despite the documentation within MSDN which suggests otherwise! Please can somebody tell me what I might be doing wrong, or perhaps there is another way to approach this problem?
Thanks
Jon
ASKER
Thanks. Just tried both of those values but neither worked - received the same error message - MAPI_E_NOT_FOUND.
MSDN documentation *does* state the value for PR_EMS_AB_ASSOC_NT_ACCOUNT as &H80270102 in a number of different places.
MSDN documentation *does* state the value for PR_EMS_AB_ASSOC_NT_ACCOUNT
Okay,
could you show some source code of yourself? Including the language you are using (I think you are using VB)...just wanna be sure. if you can show some source, I can try and debug.
regards,
CJ
could you show some source code of yourself? Including the language you are using (I think you are using VB)...just wanna be sure. if you can show some source, I can try and debug.
regards,
CJ
ASKER
Private mobjSession As MAPI.Session
'This constant is not defined by CDO (1.2, 1.21)
Private Const CdoPR_EMS_AB_ASSOC_NT_ACCO UNT = &H80270102
Public Function GetSMTPAddress(ByVal vstrUserName As String, ByVal vstrProfileName As String)
' variable declarations
Dim i As Long 'array index
Dim n As Long ' array index
Dim objAddressEntry As AddressEntry
Dim objGlobalAddressList As AddressList
Dim strSID As String ' sid
' Log on to a MAPI session
Call Session_Logon(vstrProfileN ame)
' set a reference to the global address list
Set objGlobalAddressList = GetGlobalAddressList
' loop through global address list
For i = 1 To objGlobalAddressList.Addre ssEntries. Count
Set objAddressEntry = objGlobalAddressList.Addre ssEntries( i)
' everything works until here - when I attempt to retrieve the SID
strSID = objAddressEntry.Fields.Ite m(CdoPR_EM S_AB_ASSOC _NT_ACCOUN T).Value
'This constant is not defined by CDO (1.2, 1.21)
Private Const CdoPR_EMS_AB_ASSOC_NT_ACCO
Public Function GetSMTPAddress(ByVal vstrUserName As String, ByVal vstrProfileName As String)
' variable declarations
Dim i As Long 'array index
Dim n As Long ' array index
Dim objAddressEntry As AddressEntry
Dim objGlobalAddressList As AddressList
Dim strSID As String ' sid
' Log on to a MAPI session
Call Session_Logon(vstrProfileN
' set a reference to the global address list
Set objGlobalAddressList = GetGlobalAddressList
' loop through global address list
For i = 1 To objGlobalAddressList.Addre
Set objAddressEntry = objGlobalAddressList.Addre
' everything works until here - when I attempt to retrieve the SID
strSID = objAddressEntry.Fields.Ite
I'm kinda ashaimed to ask, but what component did you exactly use that you couldget the MAPI ? I found the CDO libraries for NT and 2000, but neither one of them has those. Next to that i treid the MAPISession control,m which supplied me with almost the same items as you have in your code, but it's not the way to go if I have to follow your way (which I also would like to use).
One thing I found in the documentation is that the PR_EMS_AB_ASSOC_NT_ACCOUNT may not be supported by the underlaying system.
Anyway, before I know the correct reference I cannot debug the code...:-/
regards,
CJ
One thing I found in the documentation is that the PR_EMS_AB_ASSOC_NT_ACCOUNT
Anyway, before I know the correct reference I cannot debug the code...:-/
regards,
CJ
ASKER
Sorry, I omitted a couple of functions that I use to log on to a MAPI session & to retrieve the global address list. Both of these functions work as required, but it's not final code yet so it may be a bit messy.
The CDO library that I am using is 1.21 & I am using Visual Basic 6 SP5.
' Function: Session_Logon_NoDialog
' Purpose: Login to a MAPI session using the given profile name
Private Sub Session_Logon(ByVal vstrProfileName As String)
On Error GoTo error_olemsg
Set mobjSession = New MAPI.Session
If TypeName(mobjSession) <> "" Then
mobjSession.Logon vstrProfileName, , False, False
End If
Exit Sub
error_olemsg:
If 1273 = Err Then ' VB4.0: If Err.Number = CdoE_LOGON_FAILED Then
Err.Raise vbObjectError + 1, "JDWEmailInfo", "Cannot logon: incorrect profile name or password"
Exit Sub
End If
Err.Raise vbObjectError + 2, "JDWEmailInfo", "Error " & Str(Err) & ": " & Error$(Err)
Resume Next
End Sub
' Function: GetGlobalAddressList
' Purpose: retrieve the global address list
Private Function GetGlobalAddressList() As AddressList
On Error GoTo err_GetGlobalAddressList
If mobjSession Is Nothing Then
Err.Raise vbObjectError + 3, "JDWEmailInfo", "No active session has been created."
Exit Function
End If
Set GetGlobalAddressList = mobjSession.AddressLists(" Global Address List")
Exit Function
err_GetGlobalAddressList:
Err.Raise vbObjectError + 5, "JDWEmailInfo", "Unrecoverable Error:" & Err
Exit Function
End Function
The CDO library that I am using is 1.21 & I am using Visual Basic 6 SP5.
' Function: Session_Logon_NoDialog
' Purpose: Login to a MAPI session using the given profile name
Private Sub Session_Logon(ByVal vstrProfileName As String)
On Error GoTo error_olemsg
Set mobjSession = New MAPI.Session
If TypeName(mobjSession) <> "" Then
mobjSession.Logon vstrProfileName, , False, False
End If
Exit Sub
error_olemsg:
If 1273 = Err Then ' VB4.0: If Err.Number = CdoE_LOGON_FAILED Then
Err.Raise vbObjectError + 1, "JDWEmailInfo", "Cannot logon: incorrect profile name or password"
Exit Sub
End If
Err.Raise vbObjectError + 2, "JDWEmailInfo", "Error " & Str(Err) & ": " & Error$(Err)
Resume Next
End Sub
' Function: GetGlobalAddressList
' Purpose: retrieve the global address list
Private Function GetGlobalAddressList() As AddressList
On Error GoTo err_GetGlobalAddressList
If mobjSession Is Nothing Then
Err.Raise vbObjectError + 3, "JDWEmailInfo", "No active session has been created."
Exit Function
End If
Set GetGlobalAddressList = mobjSession.AddressLists("
Exit Function
err_GetGlobalAddressList:
Err.Raise vbObjectError + 5, "JDWEmailInfo", "Unrecoverable Error:" & Err
Exit Function
End Function
Been trying to, even installed SP5 but still don't have the MAPI libraries (CDO)...I guess I cannot help / test due to not being able to find the correct reference.
Sorry...
regards,
CJ
(ps. unless you can send me a sample VB project with the reference already set...)
Sorry...
regards,
CJ
(ps. unless you can send me a sample VB project with the reference already set...)
ASKER
i think the problem here is to do with an incorrect hex value. i'll give you the points if you can find out what the value is supposed to be!!!
the only msdn documentation that i could find:
"A property tag is a 32-bit number that contains a unique property identifier in bits 16 through 31 and a property type in bits 0 through 15"
remember 'treasure hunt' with anneka rice? this is what this is like!! ;-)
the only msdn documentation that i could find:
"A property tag is a 32-bit number that contains a unique property identifier in bits 16 through 31 and a property type in bits 0 through 15"
remember 'treasure hunt' with anneka rice? this is what this is like!! ;-)
Either that ot it just is not supported.
This is what i found:
Public Const PR_EMS_AB_ASSOC_NT_ACCOUNT = &H80270102
Maybe you find the following link useful:
http://www.outlookexchange.com/Articles/home/outlookcodeexample.asp
They have quite some development articles :-/
Regards,
CJ
This is what i found:
Public Const PR_EMS_AB_ASSOC_NT_ACCOUNT
Maybe you find the following link useful:
http://www.outlookexchange.com/Articles/home/outlookcodeexample.asp
They have quite some development articles :-/
Regards,
CJ
Nice comparison btw :-)
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
- PAQ'd and pts removed
Please leave any comments here within the
next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !
Nic;o)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Regards,
CJ