我正在尝试使用Exchange Web服务托管API和C#在Exchange服务器上远程组织电子邮件。在给定的帐户中,有一些文件夹(例如收件箱)已分配了默认策略(即“分配策略”),该默认策略将在30天后过期。帐户中的其他文件夹分配了默认策略,该策略将永不过期。
在处理项目之前,我需要找出文件夹级别的策略...这可能吗?到目前为止,我在文档中都找不到任何内容。
此外,如果有人知道如何在VBA中执行相同的任务,那么我相信这也会在某个时候派上用场。
谢谢。
答案 0 :(得分:0)
您可以从PolicyTag属性https://msdn.microsoft.com/EN-US/library/microsoft.exchange.webservices.data.folder.policytag(v=exchg.80).aspx获取该策略,这将为您提供GUID,您可以使用Exchange Service类https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.exchangeservice.getuserretentionpolicytags?view=exchange-ews-api
上的GetRetentionTags方法来解析该GUID。您可以通过发布RAW SOAP并通过非常简单的示例(例如在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