Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private ExchangeBinding As New ExchangeServiceBinding
- Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal Domain As String, ByVal URL As String)
- ExchangeBinding.Credentials = New NetworkCredential(UserName, Password, Domain)
- ExchangeBinding.Url = URL
- End Sub
- Dim returnInboxMessageIds As ArrayOfRealItemsType = Nothing
- Dim errMsg As String = String.Empty
- 'Create the request and specify the travesal type.
- Dim FindItemRequest As FindItemType
- FindItemRequest = New FindItemType
- FindItemRequest.Traversal = ItemQueryTraversalType.Shallow
- 'Define which item properties are returned in the response.
- Dim ItemProperties As ItemResponseShapeType
- ItemProperties = New ItemResponseShapeType
- ItemProperties.BaseShape = DefaultShapeNamesType.IdOnly
- 'Add properties shape to the request.
- FindItemRequest.ItemShape = ItemProperties
- 'Identify which folders to search to find items.
- Dim FolderIDArray(0) As DistinguishedFolderIdType
- FolderIDArray(0) = New DistinguishedFolderIdType
- FolderIDArray(0).Id = DistinguishedFolderIdNameType.inbox
- 'Add folders to the request.
- FindItemRequest.ParentFolderIds = FolderIDArray
- Try
- 'Send the request and get the response.
- Dim FindItemResponse As FindItemResponseType
- FindItemResponse = ExchangeBinding.FindItem(FindItemRequest)
- 'Get the response messages.
- Dim ResponseMessage As ResponseMessageType()
- ResponseMessage = FindItemResponse.ResponseMessages.Items
- Dim FindItemResponseMessage As FindItemResponseMessageType
- If ResponseMessage(0).ResponseClass = ResponseClassType.Success Then
- FindItemResponseMessage = ResponseMessage(0)
- returnInboxMessageIds = FindItemResponseMessage.RootFolder.Item
- Else
- '' Server error
- Dim responseClassStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseClassType), ResponseMessage(0).ResponseClass).ToString
- Dim responseCodeStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseCodeType), ResponseMessage(0).ResponseCode).ToString
- Dim messageTextStr As String = ResponseMessage(0).MessageText.ToString
- Dim thisErrMsg As String = String.Format("ExchangeWebServices Inbox Error: {0}, {1}, {2}", responseClassStr, responseCodeStr, messageTextStr)
- errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & thisErrMsg
- End If
- Catch ex As Exception
- errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & ex.Message
- End Try
- If Not errMsg.Equals(String.Empty) Then
- returnInboxMessageIds = Nothing
- Throw New System.Exception(errMsg)
- End If
- Return returnInboxMessageIds
- End Function
- -ExchangeServiceBinding
- -ArrayOfRealItemsType
- -FindItemType
- -ItemQueryTraversalType
- -ItemResponseShapeType
- -DefaultShapeNamesType
- -DistinguishedFolderIdType
- -DistinguishedFolderIdNameType
- -FindItemResponseType
- -ResponseMessageType()
- -FindItemResponseMessageType
- -ResponseClassType
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement