使用 PowerShell,我可以调用 Get-MailPublicFolder 来检索有关启用 Exchange 邮件的公用文件夹的邮件相关信息。
我想使用 EWS 做同样的事情。尤其是获取公共文件夹电子邮件地址。
到目前为止,我已经设法将公共文件夹作为 Microsoft.Exchange.WebServices.Data.Folder 对象的列表。但我看不到返回文件夹电子邮件地址的文件夹对象上的属性。我检查了 ExtendedProperties 属性,它是一个空列表。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("joe.bloggs@microsoft.com");
Folder rootfolder = Folder.Bind(service, WellKnownFolderName.PublicFoldersRoot);
FolderView folderView = new FolderView(1000);
foreach (Folder folder in rootfolder.FindFolders(folderView))
{
folder.Load();
System.Diagnostics.Debug.WriteLine("Folder Name: " + folder.DisplayName);
if (folder.ExtendedProperties.Count > 0)
{
foreach (ExtendedProperty ep in folder.ExtendedProperties)
{
System.Diagnostics.Debug.WriteLine(" " + ep.PropertyDefinition.Name + " = " + ep.Value);
}
}
}
有人可以向我展示如何使用 EWS 进行操作的示例吗?
谢谢
更新
我已将 Shay 发布的代码转换为 C#,它可以工作:)
下面是转换成 C# 的代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("joe.bloggs@microsoft.com");
Folder rootfolder = Folder.Bind(service, WellKnownFolderName.PublicFoldersRoot);
FolderView folderView = new FolderView(1000);
ExtendedPropertyDefinition proxyProp = new ExtendedPropertyDefinition(26397, MapiPropertyType.Binary);
folderView.PropertySet = new PropertySet(proxyProp);
foreach (Folder folder in rootfolder.FindFolders(folderView))
{
object objectGuid;
if (folder.TryGetProperty(proxyProp, out objectGuid))
{
objectGuid = System.BitConverter.ToString((byte[])objectGuid).Replace("-", "");
var adFolder = new DirectoryEntry(string.Format("LDAP://<GUID={0}>", objectGuid.ToString()));
var mailVal = adFolder.Properties["Mail"].Value;
}
}