I've been working with the Exchange Web Service (EWS) Managed API wrapper to perform some Exchange tasks. My WEBDAV code wouldn't work with Exchange 2007.
The EWS Managed API is much easier to work with then the direct Exchange web service calls. Thanks goodness.
One task I have is to process inbound mail and flag it as complete. Took me hours to figure it out. First I have a search folder that has the stuff I want to process. This makes it easier to change the business rules in the outlook client rather than the code in the future. Then the processing takes place and the flags are set to mark the message as complete.
What flags to set are defined in the [MS-OXOFLAG]: Informational Flagging Protocol Specification http://msdn.microsoft.com/en-us/library/cc433487.aspx
Dim service As New ExchangeService(ExchangeVersion.Exchange2007_SP1)
service.Url = New Uri("https:/exchangeServer/ews/exchange.asmx")
service.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
'Get the search Folder by name
Dim searchFolderName As String = "UnflaggedTest"
Dim fr As FindFoldersResults = service.FindFolders(WellKnownFolderName.SearchFolders, New FolderView(10))
Dim searchFolder As SearchFolder = Nothing
For Each searchFolder In fr.Folders
If searchFolder.DisplayName = searchFolderName Then
Exit For
End If
Next
If searchFolder.DisplayName <> searchFolderName Then
Exit Sub
End If
Dim item As Item
Dim items As FindItemsResults(Of Item) = service.FindItems(searchFolder.Id, New ItemView(10))
For Each item In items.Items
Dim epd_PidTagFlagStatus As New ExtendedPropertyDefinition(&H1090, MapiPropertyType.Integer) 'PidTagFlagStatus
Dim epd_PidTagFlagCompleteTime As New ExtendedPropertyDefinition(&H1091, MapiPropertyType.SystemTime) 'PidTagFlagCompleteTime
Dim epd_PidLidFlagRequest As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, &H8530, MapiPropertyType.String) 'PidLidFlagRequest
Dim epd_PidLidFlagString As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, &H85C0, MapiPropertyType.Integer) 'PidLidFlagString
Dim epd_PidLidValidFlagStringProof As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, &H85BF, MapiPropertyType.SystemTime) 'PidLidValidFlagStringProof
Dim epd_PidTagFollowupIcon As New ExtendedPropertyDefinition(&H1095, MapiPropertyType.Integer) 'PidTagFollowupIcon
Dim epd_PidTagMessageDeliveryTime As New ExtendedPropertyDefinition(&HE06, MapiPropertyType.SystemTime) 'PidTagMessageDeliveryTime
Dim psExtProps As New PropertySet(BasePropertySet.FirstClassProperties, _
epd_PidTagFlagStatus, epd_PidTagFlagCompleteTime, epd_PidLidFlagRequest, epd_PidLidFlagString, epd_PidLidValidFlagStringProof, epd_PidTagFollowupIcon, epd_PidTagMessageDeliveryTime)
Dim msg As EmailMessage = EmailMessage.Bind(service, item.Id, psExtProps)
Dim msgBody As String
Dim msgSubject As String
msgBody = msg.Body.Text
msgSubject = msg.Subject
Dim sOut As String = ""
msg.ExtendedProperties.TryGetValue(epd_PidTagFlagStatus, sOut)
Debug.Print("PidTagFlagStatus: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidTagFlagCompleteTime, sOut)
Debug.Print("PidTagFlagCompleteTime: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidLidFlagRequest, sOut)
Debug.Print("PidLidFlagRequest: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidLidFlagString, sOut)
Debug.Print("PidLidFlagString: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidLidValidFlagStringProof, sOut)
Debug.Print("PidLidValidFlagStringProof: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidTagFollowupIcon, sOut)
Debug.Print("PidTagFollowupIcon: " & sOut)
sOut = ""
msg.ExtendedProperties.TryGetValue(epd_PidTagMessageDeliveryTime, sOut)
Debug.Print("PidTagMessageDeliveryTime: " & sOut)
sOut = ""
Dim msgDelTime As DateTime
msg.ExtendedProperties.TryGetValue(epd_PidTagMessageDeliveryTime, msgDelTime)
msg.SetExtendedProperty(epd_PidTagFlagStatus, 1) 'PidTagFlagStatus
msg.SetExtendedProperty(epd_PidTagFlagCompleteTime, Now) 'PidTagFlagCompleteTime
msg.SetExtendedProperty(epd_PidLidFlagString, &H3) 'PidLidFlagString
msg.SetExtendedProperty(epd_PidLidValidFlagStringProof, msgDelTime) 'PidLidValidFlagStringProof
msg.ExtendedProperties.Remove(epd_PidTagFollowupIcon) 'PidTagFollowupIcon
msg.IsRead = True
msg.Update(ConflictResolutionMode.NeverOverwrite)
Next
Print | posted on Wednesday, July 1, 2009 3:43 PM