[英]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.我正在尝试使用 Exchange Web Services Managed API 和 C# 在 Exchange 服务器上远程组织电子邮件。 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.
在给定的帐户中,有些文件夹(例如收件箱)分配了默认策略(即“分配策略”),这些策略将在 30 天后使项目过期。 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.此外,如果有人知道如何在 VBA 中执行相同的任务,我相信这也会在某些时候派上用场。
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您可以从 PolicyTag 属性https://msdn.microsoft.com/EN-US/library/microsoft.exchange.webservices.data.folder.policytag(v=exchg.80).aspx获取策略,这将为您提供您可以使用 Exchange 服务类上的 GetRetentionTags 方法解析 GUID 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你可以在 VBA 中做同样的事情,发布 RAW SOAP 并处理响应,这只是一个耗时的过程,例如在 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.