Module Module1
Sub Main()
Dim oCn As ADODB.Connection = New ADODB.Connection()
Dim oRs As ADODB.Recordset = New ADODB.Recordset()
Dim oFields As ADODB.Fields
Dim oField As ADODB.Field
' TODO: Replace with your folder URL
Dim sFdUrl As String
sFdUrl = "http://<ExchServer>/Exchange/<UserAlias>/Inbox"
oCn.Provider = "exoledb.datasource"
oCn.Open(sFdUrl, "", "", -1)
If oCn.State = 1 Then
Console.WriteLine("Good Connection")
Else
Console.WriteLine("Bad Connection")
Return
End If
' TODO: You may want to retrieve more properties.
Dim strSql As String
strSql = ""
strSql = "select "
strSql = strSql + " ""urn:schemas:mailheader:content-class"""
strSql = strSql + ", ""DAV:href"" "
strSql = strSql + ", ""urn:schemas:mailheader:content-class"" "
strSql = strSql + ", ""DAV:displayname"""
strSql = strSql + " from scope ('shallow traversal of " + """"
strSql = strSql + sFdUrl + """') "
strSql = strSql + " WHERE ""DAV:ishidden"" = false"
strSql = strSql + " AND ""DAV:isfolder"" = false"
oRs.Open(strSql, oCn, _
ADODB.CursorTypeEnum.adOpenUnspecified, _
ADODB.LockTypeEnum.adLockOptimistic, 1)
' Example: Get the first message.
' A loop can also be written to iterate through all the messages.
oRs.MoveFirst()
' get Recordset fields
oFields = oRs.Fields
' List all fields.
'Dim i As Integer
'For i = 0 To oFields.Count - 1
' oField = oFields.Item(i)
' Console.WriteLine("{0} : {1}", oField.Name, oField.Value)
'Next
' Get the item URL.
Dim sURL As String
oField = oFields.Item("DAV:href")
sURL = oField.Value.ToString()
Console.WriteLine(sURL)
' You can also open the item with the Message object.
Dim iMsg As CDO.Message = New CDO.Message()
iMsg.DataSource.Open(sURL, oRs.ActiveConnection, _
ADODB.ConnectModeEnum.adModeReadWrite, _
ADODB.RecordCreateOptionsEnum.adFailIfNotExists, _
ADODB.RecordOpenOptionsEnum.adOpenSource, _
"", "")
Console.WriteLine("{0}", iMsg.Sender)
Console.WriteLine("{0}", iMsg.Subject)
Console.WriteLine("{0}", iMsg.TextBody)
' List the message fields.
oFields = iMsg.Fields
For i = 0 To oFields.Count - 1
oField = oFields.Item(i)
Console.WriteLine("{0} : {1}", oField.Name, oField.Value)
Next
oRs.Close()
oCn.Close()
oCn = Nothing
oRs = Nothing
oFields = Nothing
oField = Nothing
'Use the following line to persist the console window for examination.
Console.ReadLine()
End Sub
End Module