简体   繁体   English

如何使用 C# 和 Exchange Web Services Managed API 获取文件夹的策略?

[英]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.

相关问题 如何使用Exchange Web Services 2010托管API获取文件夹大小? - How do I get folder size with Exchange Web Services 2010 Managed API? 使用C#中的Exchange Web服务托管API检索错误的邮箱项目 - Wrong mailbox items being retrieved using Exchange Web Services managed API in C# Folder.Bind - “Id格式错误” - Exchange Web服务托管API - Folder.Bind - “Id is malformed” - Exchange Web Services Managed API C# 交换 Web 服务托管 API 模拟 -&gt; Microsoft Graph ZDB974238714CA8DE634A7CE108A14F - C# Exchange Web Services Managed API Impersonation -> Microsoft Graph API 使用交换Web服务获取日历项目所需的参与者? C# - Using exchange web services to get the required attendees of a calendaritem? c# 如何使用Exchange Web Services在C#中更改电子邮件主题 - How to change email subject in C# using Exchange Web Services 如何使用Exchange Web服务托管API列出这些文件夹中的所有文件夹和文件? - How to list all folders and files in those folders using Exchange Web Services Managed API? 如何在托管的Exchange Web服务中更改AppointmentStatus - How to change AppointmentStatus in managed Exchange Web Services 使用Exchange Web Services从C#中的自定义和已发送邮件文件夹获取电子邮件 - Get emails from custom and sent mail folders in c# using Exchange Web Services 是否可以使用c#中的Exchange Web服务分配角色? - Is it possible to assign roles using the Exchange web services in c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM