Reputation: 2018
Using PowerShell I can call Get-MailPublicFolder to retrieve mail-related information about Exchange mail-enabled public folders.
I want to do the same thing using EWS. And in particular get the Public Folder Email Addresses.
So far I've managed to get the Public Folders as a list of Microsoft.Exchange.WebServices.Data.Folder objects. But I can't see a property on the Folder object that returns the Folder Email Addresses. And I've checked the ExtendedProperties property and it's an empty list.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("[email protected]");
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);
}
}
}
Can someone please show me an example on how to do it using EWS?
Thank you
I've converted the code Shay posted into C#, and it works :)
Here is the code converted into C#:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("[email protected]");
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;
}
}
Upvotes: 2
Views: 1931
Reputation: 126702
I'm able to get it with the following, you'll need to translate it to c#. The result is a folder object extended with an Email property.
$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
}
Upvotes: 2