简体   繁体   中英

How to get a folder's policy using C# and Exchange Web Services Managed API?

I'm trying to use Exchange Web Services Managed API and C# to organize emails remotely on an Exchange server. Within a given account, there are some folders, such as Inbox, that have a default policy assigned (ie "Assign Policy") that will expire items after 30 days. Other folders in the account have a default policy assigned that will never expire items.

I need to find out what the policy is at the folder level before I process the items...is this possible? I have been unable to find anything in the documentation so far.

Also, if anyone knows how to perform the same task in VBA, I'm sure that will come in handy at some point, as well.

Thanks.

You can get the Policy from the PolicyTag property https://msdn.microsoft.com/EN-US/library/microsoft.exchange.webservices.data.folder.policytag(v=exchg.80).aspx which will give you the GUID you can resolve using the GetRetentionTags method on the Exchange Service class https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.exchangeservice.getuserretentionpolicytags?view=exchange-ews-api

You can do the same thing in VBA by posting the RAW SOAP and processing the responses its just a time consuming process through eg really simple example of sending a message in VBA

 Sub SendMessage(Subject As String, Recipient As String, Body As String, User As String, Password As String) Dim sReq As String Dim xmlMethod As String Dim XMLreq As New MSXML2.XMLHTTP60 Dim EWSEndPoint As String EWSEndPoint = "https://outlook.office365.com/EWS/Exchange.asmx" sReq = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf sReq = sReq & "<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">" & vbCrLf sReq = sReq & "<soap:Header>" & vbCrLf sReq = sReq & "<t:RequestServerVersion Version=""Exchange2010""/>" & vbCrLf sReq = sReq & "</soap:Header>" & vbCrLf sReq = sReq & "<soap:Body>" & vbCrLf sReq = sReq & "<CreateItem MessageDisposition=""SendAndSaveCopy"" xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages"">" & vbCrLf sReq = sReq & "<SavedItemFolderId>" & vbCrLf sReq = sReq & "<t:DistinguishedFolderId Id=""sentitems"" />" & vbCrLf sReq = sReq & "</SavedItemFolderId>" & vbCrLf sReq = sReq & "<Items>" & vbCrLf sReq = sReq & "<t:Message>" & vbCrLf sReq = sReq & "<t:ItemClass>IPM.Note</t:ItemClass>" & vbCrLf sReq = sReq & "<t:Subject>" & Subject & "</t:Subject>" & vbCrLf sReq = sReq & "<t:Body BodyType=""Text"">" & Body & "</t:Body>" & vbCrLf sReq = sReq & "<t:ToRecipients>" & vbCrLf sReq = sReq & " <t:Mailbox>" & vbCrLf sReq = sReq & " <t:EmailAddress>" & Recipient & "</t:EmailAddress>" & vbCrLf sReq = sReq & " </t:Mailbox>" & vbCrLf sReq = sReq & "</t:ToRecipients>" & vbCrLf sReq = sReq & "</t:Message>" & vbCrLf sReq = sReq & "</Items>" & vbCrLf sReq = sReq & "</CreateItem>" & vbCrLf sReq = sReq & "</soap:Body>" & vbCrLf sReq = sReq & "</soap:Envelope>" & vbCrLf xmlMethod = "POST" XMLreq.Open xmlMethod, EWSEndPoint, False, User, Password XMLreq.setRequestHeader "Content-Type", "text/xml; charset=""UTF-8""" XMLreq.setRequestHeader "Translate", "F" XMLreq.setRequestHeader "User-Agent", "VBAEWSSender" XMLreq.send sReq If XMLreq.Status = 200 Then ' Message Sent okay Else ' Something went Wrong End If End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM