Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. Private ExchangeBinding As New ExchangeServiceBinding
  2. Public Sub New(ByVal UserName As String, ByVal Password As String, ByVal Domain As String, ByVal URL As String)
  3. ExchangeBinding.Credentials = New NetworkCredential(UserName, Password, Domain)
  4. ExchangeBinding.Url = URL
  5. End Sub
  6.  
  7. Dim returnInboxMessageIds As ArrayOfRealItemsType = Nothing
  8. Dim errMsg As String = String.Empty
  9.  
  10. 'Create the request and specify the travesal type.
  11. Dim FindItemRequest As FindItemType
  12. FindItemRequest = New FindItemType
  13. FindItemRequest.Traversal = ItemQueryTraversalType.Shallow
  14.  
  15. 'Define which item properties are returned in the response.
  16. Dim ItemProperties As ItemResponseShapeType
  17. ItemProperties = New ItemResponseShapeType
  18. ItemProperties.BaseShape = DefaultShapeNamesType.IdOnly
  19.  
  20. 'Add properties shape to the request.
  21. FindItemRequest.ItemShape = ItemProperties
  22.  
  23. 'Identify which folders to search to find items.
  24. Dim FolderIDArray(0) As DistinguishedFolderIdType
  25. FolderIDArray(0) = New DistinguishedFolderIdType
  26. FolderIDArray(0).Id = DistinguishedFolderIdNameType.inbox
  27.  
  28. 'Add folders to the request.
  29. FindItemRequest.ParentFolderIds = FolderIDArray
  30.  
  31. Try
  32. 'Send the request and get the response.
  33. Dim FindItemResponse As FindItemResponseType
  34. FindItemResponse = ExchangeBinding.FindItem(FindItemRequest)
  35.  
  36. 'Get the response messages.
  37. Dim ResponseMessage As ResponseMessageType()
  38. ResponseMessage = FindItemResponse.ResponseMessages.Items
  39.  
  40. Dim FindItemResponseMessage As FindItemResponseMessageType
  41.  
  42. If ResponseMessage(0).ResponseClass = ResponseClassType.Success Then
  43.  
  44. FindItemResponseMessage = ResponseMessage(0)
  45. returnInboxMessageIds = FindItemResponseMessage.RootFolder.Item
  46.  
  47. Else
  48.  
  49. '' Server error
  50. Dim responseClassStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseClassType), ResponseMessage(0).ResponseClass).ToString
  51. Dim responseCodeStr As String = [Enum].GetName(GetType(ExchangeWebServices.ResponseCodeType), ResponseMessage(0).ResponseCode).ToString
  52. Dim messageTextStr As String = ResponseMessage(0).MessageText.ToString
  53. Dim thisErrMsg As String = String.Format("ExchangeWebServices Inbox Error: {0}, {1}, {2}", responseClassStr, responseCodeStr, messageTextStr)
  54. errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & thisErrMsg
  55.  
  56. End If
  57.  
  58. Catch ex As Exception
  59. errMsg = If(errMsg.Equals(String.Empty), String.Empty, errMsg & "; ") & ex.Message
  60. End Try
  61.  
  62. If Not errMsg.Equals(String.Empty) Then
  63. returnInboxMessageIds = Nothing
  64. Throw New System.Exception(errMsg)
  65. End If
  66.  
  67. Return returnInboxMessageIds
  68.  
  69. End Function
  70.  
  71. -ExchangeServiceBinding
  72. -ArrayOfRealItemsType
  73. -FindItemType
  74. -ItemQueryTraversalType
  75. -ItemResponseShapeType
  76. -DefaultShapeNamesType
  77. -DistinguishedFolderIdType
  78. -DistinguishedFolderIdNameType
  79. -FindItemResponseType
  80. -ResponseMessageType()
  81. -FindItemResponseMessageType
  82. -ResponseClassType
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement