| Author |
Message |
davemateer@gmail.com
Guest
|
Posted:
Fri Nov 04, 2005 9:58 am Post subject:
CDOEX - logged in user problems - impersonate? |
|
|
Hi (**after days spent in this are I finally have something working!**)
I have the following code (straight from the Exchange SDK VB6 Messaging
example):
It works locally on the Exchange Server, only if I am logged in to that
exchange server as the same person I am querying. In this case,
davetest.
How can I query other users' mailboxes using this appoach?
I've decided to try this way rather than webdav as app will always be
on the exchange server.
Kind Regards, Dave.
'References CDO For Exchange, and ActiveX Data Objects 2.5 Library
' some code before this...
strEmailAddress = "davetest@dummyname.co.nz"
' Create a CDOEX Person object. This will be used to determine the URL
of the user's Inbox.
Dim iPerson As New CDO.Person
' Create an ADO Recordset object. This will be used to hold the message
items that are in the users Inbox.
Dim rstInbox As New ADODB.Recordset
' Create an ADO Connection object. This will be used to
' make a connection to the Exchange Store using the the EXOLEDB data
provider.
Dim conInbox As New ADODB.Connection
' Create a mailbox interface. This will be used to get the user's Inbox
URL.
Dim iMailbox As iMailbox
Dim strEmail As String
Dim strInboxQuery As String
strEmail = "mailto:" & strEmailAddress
' Get data for the Person object. This will be used to get the users
Inbox url.
iPerson.DataSource.Open strEmail
' Get the Mailbox interface from the Person object for the user.
Set iMailbox = iPerson.GetInterface("IMailbox")
'Doing this so can see exactly what is passed
Dim dave As String
dave =
"file://./backofficestorage/dummyname.co.nz/MBX/davetest/Inbox"
' Set up a query to get all the items in the user's Inbox that are not
hidden or a folder.
strInboxQuery = "select " & _
"""DAV:href""" & _
"from scope('shallow traversal of """ & dave &
"""')" & _
"where ""DAV:ishidden"" = false and" & _
" ""DAV:isfolder"" = false"
' Set the ADO Connection object properties to open the user's Inbox.
With conInbox
.Provider = "exoledb.datasource"
.Open iMailbox.Inbox
End With
' Use the ADO Connection object and the Query mentioned above to get
the items that are located in the user's Inbox.
rstInbox.Open strInboxQuery, conInbox
If rstInbox.RecordCount = 0 Then
lstInbox.AddItem "No items in Inbox!"
btnReply.Enabled = False
btnForward.Enabled = False
lblInboxFrom.Caption = ""
lblInboxSubject.Caption = ""
lblInboxBody.Caption = ""
Else
While Not rstInbox.EOF
lstInbox.AddItem rstInbox(0)
rstInbox.MoveNext
Wend
End If
|
|
| Back to top |
|
 |
Glen Scales [MVP]
Guest
|
Posted:
Mon Nov 07, 2005 1:58 am Post subject:
Re: CDOEX - logged in user problems - impersonate? |
|
|
CDOEX access's the Exchange store over Exoledb which has no provision to
allow you to enter alternate credentials so your code will always run under
the security context of the process that's calling it. To access a mailbox
you need to have rights to that mailbox if you had a piece of code you
needed to access every mailbox on a Exchange server you would first need to
create an account that had full rights to the mailstore see
http://support.microsoft.com/?kbid=262054 . You can then use something like
a Com+ wrapper to set the identity your code will run under.
Cheers
Glen
<davemateer@gmail.com> wrote in message
news:1131081984.178904.290890@g49g2000cwa.googlegroups.com...
| Quote: | Hi (**after days spent in this are I finally have something working!**)
I have the following code (straight from the Exchange SDK VB6 Messaging
example):
It works locally on the Exchange Server, only if I am logged in to that
exchange server as the same person I am querying. In this case,
davetest.
How can I query other users' mailboxes using this appoach?
I've decided to try this way rather than webdav as app will always be
on the exchange server.
Kind Regards, Dave.
'References CDO For Exchange, and ActiveX Data Objects 2.5 Library
' some code before this...
strEmailAddress = "davetest@dummyname.co.nz"
' Create a CDOEX Person object. This will be used to determine the URL
of the user's Inbox.
Dim iPerson As New CDO.Person
' Create an ADO Recordset object. This will be used to hold the message
items that are in the users Inbox.
Dim rstInbox As New ADODB.Recordset
' Create an ADO Connection object. This will be used to
' make a connection to the Exchange Store using the the EXOLEDB data
provider.
Dim conInbox As New ADODB.Connection
' Create a mailbox interface. This will be used to get the user's Inbox
URL.
Dim iMailbox As iMailbox
Dim strEmail As String
Dim strInboxQuery As String
strEmail = "mailto:" & strEmailAddress
' Get data for the Person object. This will be used to get the users
Inbox url.
iPerson.DataSource.Open strEmail
' Get the Mailbox interface from the Person object for the user.
Set iMailbox = iPerson.GetInterface("IMailbox")
'Doing this so can see exactly what is passed
Dim dave As String
dave =
"file://./backofficestorage/dummyname.co.nz/MBX/davetest/Inbox"
' Set up a query to get all the items in the user's Inbox that are not
hidden or a folder.
strInboxQuery = "select " & _
"""DAV:href""" & _
"from scope('shallow traversal of """ & dave &
"""')" & _
"where ""DAV:ishidden"" = false and" & _
" ""DAV:isfolder"" = false"
' Set the ADO Connection object properties to open the user's Inbox.
With conInbox
.Provider = "exoledb.datasource"
.Open iMailbox.Inbox
End With
' Use the ADO Connection object and the Query mentioned above to get
the items that are located in the user's Inbox.
rstInbox.Open strInboxQuery, conInbox
If rstInbox.RecordCount = 0 Then
lstInbox.AddItem "No items in Inbox!"
btnReply.Enabled = False
btnForward.Enabled = False
lblInboxFrom.Caption = ""
lblInboxSubject.Caption = ""
lblInboxBody.Caption = ""
Else
While Not rstInbox.EOF
lstInbox.AddItem rstInbox(0)
rstInbox.MoveNext
Wend
End If
|
|
|
| Back to top |
|
 |
davemateer@gmail.com
Guest
|
Posted:
Wed Nov 09, 2005 9:58 am Post subject:
Re: CDOEX - logged in user problems - impersonate? |
|
|
Glen
Many thanks again.. that certainly explains the issues I've been
having.
If you ever need a beer in NZ look me up.
Dave.
|
|
| Back to top |
|
 |
|
|
|
|