如何使用EWS检索有关启用Exchange邮件的公用文件夹的邮件相关信息

本文关键字:信息 文件夹 Exchange EWS 何使用 检索 启用 | 更新日期: 2023-09-27 18:19:06

使用PowerShell,我可以调用Get-MailPublicFolder来检索关于启用Exchange邮件的公共文件夹的邮件相关信息。

我想用EWS做同样的事情。特别是获取公共文件夹的电子邮件地址。

到目前为止,我已经设法将公共文件夹作为Microsoft.Exchange.WebServices.Data.Folder对象的列表。但是我在Folder对象上看不到返回Folder Email Addresses的属性。我检查了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;
    }
}

如何使用EWS检索有关启用Exchange邮件的公用文件夹的邮件相关信息

我可以用下面的代码得到它,你需要把它翻译成c#。结果是一个带有Email属性的文件夹对象。

$PR_PF_PROXY = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition 26397,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary
$view.PropertySet.Add($PR_PF_PROXY) 
$foldersResult = $ExchangeService.FindFolders(Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::PublicFoldersRoot,$view)
    foreach($folder in $foldersResult.Folders)
    {  
        $folder = $folder | Add-Member -MemberType NoteProperty -Name Email -Value $null -PassThru
        $guid=$null
        if($folder.TryGetProperty($PR_PF_PROXY,[ref]$guid))
        {
            $dn=[bitconverter]::ToString($guid) -replace '-'
            $folder.Email = ([ADSI]"LDAP://<GUID=$dn>").Properties.mail.value
        }
        $folder
    }