gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:02:25 26 4
gpt4 key购买 nike

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

我想使用 EWS 做同样的事情。尤其是获取公共(public)文件夹电子邮件地址。

到目前为止,我已经设法将公用文件夹作为 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;
}
}

最佳答案

我可以通过以下方式获取它,您需要将其转换为 C#。结果是使用电子邮件属性扩展的文件夹对象。

$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
}

关于c# - 如何使用 EWS 检索有关已启用 Exchange 邮件的公用文件夹的邮件相关信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17211270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com