Skip to main content

Changing OWA configuration setting with EWS in Exchange 2010

The ability to change and customise the default configuration of OWA is an often sort out and in previous versions of Exchange hard to achieve task. Especially for those with Large Exchange Orgs and standardised training or custom security requirements where the default settings come into conflict with other policies. Underlying a lot of OWA configuration settings are stored in FAI items (folder associated items) in a users mailbox using the Configuration Information Protocol Specification documented in http://msdn.microsoft.com/en-us/library/cc463899(EXCHG.80).aspx.

Along with the ability to access FAI items which was previously not possible in Exchange 2007 using EWS, Exchange 2010 also introduces a new UserConfiguration Operation in EWS that provides some Typed objects the makes dealing with configuration objects a lot easier and safer for those that wish to do so. (I still wouldn't guarantee the support response you would get if you do use these Operations and stuff your Exchange Org completely this is a risk you should understand before undertaking such an endeavor). What having these strong objects to use if your using Proxy code or the EWS Managed API means is that a task that may have taken a lot effort and reverse engineering in the past to achieve is really now something you can do fairly easy with a couple of lines of code or script.

The User configuration FAI items can be located in different folders in a Mailbox the one im going to focus on in this post is the OWA.UserOptions object which contain things such as the readingpane setting, OWA signiture and other general settings. The message itself has a message class of IPM.Configuration.OWA.UserOptions if you looked at it with a Mapi editor and its located in the Non_IPM_Subtree (ed Note since the removal of Dav in Exchange 2010 is this still the right terminology??).

This brings up an important point for anybody trying to modify these type of objects one tool you will find invaluable is a Mapi editory like the MFCMapi or OutlookSpy. Another useful tool is now the EWS editor these two tools will make doing this type of thing a lot eaiser as they can allow you to browse and see the current values of properties on items. You should also read the the protocol document i linked above and have an understanding of the datatypes involved with the properties your setting and make sure you adhere to this. Eg dont use a String where a Interger is expected etc.

For this post im also using the EWS Managed API which saves time and sanity when writing EWS code.

Lets get down to the code the first thing you need to do is get the FolderID for the Non_Ipm_Subtee, to do this you Bind to the Root folder and use the parentFolderID property

Folder Root = Folder.Bind(service, WellKnownFolderName.Root);

Next you use the UserConfiguration objects bind method and pass the following parameters in

UserConfiguration OWAConfig = UserConfiguration.Bind(service, "OWA.UserOptions", Root.ParentFolderId, UserConfigurationProperties.All);

Note that you take the MessageClass of the Item IPM.Configuration.OWA.UserOptions and drop the IPM.Configuration part.

This will then get the existing configuration object settings from this particular folder item which for this item will be returned as a dictionary collection. If you want to enum through all the properties you can do the following

IDictionaryEnumerator ConfigEnum = (IDictionaryEnumerator)OWAConfig.Dictionary.GetEnumerator();
while (ConfigEnum.MoveNext()) {
Console.WriteLine("Key : " + ConfigEnum.Key);
Console.WriteLine("Value : " + ConfigEnum.Value);
}


To Set a value it pretty simple eg

if(OWAConfig.Dictionary.ContainsKey("previewmarkasread")){
OWAConfig.Dictionary["previewmarkasread"] = 2;
}
else{
OWAConfig.Dictionary.Add("previewmarkasread", 2);
}
OWAConfig.Update();

This turns the Mark as Read off in the previewpane in OWA note that this is a Intager value.

To do this in Powershell script that you could feed with get-mailbox it would look like the following I've put a download of the code here

$MailboxName = "user@domain.com"

$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\1.0\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)

$windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sidbind = "LDAP://<SID=" + $windowsIdentity.user.Value.ToString() + ">"
$aceuser = [ADSI]$sidbind

$service.AutodiscoverUrl($mailboxname)

$folderid = new-object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$Root = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
$OWAConfig = [Microsoft.Exchange.WebServices.Data.UserConfiguration]::Bind($service, "OWA.UserOptions", $Root.ParentFolderId, [Microsoft.Exchange.WebServices.Data.UserConfigurationProperties]::All)
if($OWAConfig.Dictionary.ContainsKey("previewmarkasread")){
$OWAConfig.Dictionary["previewmarkasread"] = 2 }
else{
$OWAConfig.Dictionary.Add("previewmarkasread", 2)
}
$OWAConfig.Update()
"Done"

Popular posts from this blog

The MailboxConcurrency limit and using Batching in the Microsoft Graph API

If your getting an error such as Application is over its MailboxConcurrency limit while using the Microsoft Graph API this post may help you understand why. Background   The Mailbox  concurrency limit when your using the Graph API is 4 as per https://docs.microsoft.com/en-us/graph/throttling#outlook-service-limits . This is evaluated for each app ID and mailbox combination so this means you can have different apps running under the same credentials and the poor behavior of one won't cause the other to be throttled. If you compared that to EWS you could have up to 27 concurrent connections but they are shared across all apps on a first come first served basis. Batching Batching in the Graph API is a way of combining multiple requests into a single HTTP request. Batching in the Exchange Mail API's EWS and MAPI has been around for a long time and its common, for email Apps to process large numbers of smaller items for a variety of reasons.  Batching in the Gr...

Sending a Message in Exchange Online via REST from an Arduino MKR1000

This is part 2 of my MKR1000 article, in this previous post  I looked at sending a Message via EWS using Basic Authentication.  In this Post I'll look at using the new Outlook REST API  which requires using OAuth authentication to get an Access Token. The prerequisites for this sketch are the same as in the other post with the addition of the ArduinoJson library  https://github.com/bblanchon/ArduinoJson  which is used to parse the Authentication Results to extract the Access Token. Also the SSL certificates for the login.windows.net  and outlook.office365.com need to be uploaded to the devices using the wifi101 Firmware updater. To use Token Authentication you need to register an Application in Azure https://msdn.microsoft.com/en-us/office/office365/howto/add-common-consent-manually  with the Mail.Send permission. The application should be a Native Client app that use the Out of Band Callback urn:ietf:wg:oauth:2.0:oob. You ...

How to test SMTP using Opportunistic TLS with Powershell and grab the public certificate a SMTP server is using

Most email services these day employ Opportunistic TLS when trying to send Messages which means that wherever possible the Messages will be encrypted rather then the plain text legacy of SMTP.  This method was defined in RFC 3207 "SMTP Service Extension for Secure SMTP over Transport Layer Security" and  there's a quite a good explanation of Opportunistic TLS on Wikipedia  https://en.wikipedia.org/wiki/Opportunistic_TLS .  This is used for both Server to Server (eg MTA to MTA) and Client to server (Eg a Message client like Outlook which acts as a MSA) the later being generally Authenticated. Basically it allows you to have a normal plain text SMTP conversation that is then upgraded to TLS using the STARTTLS verb. Not all servers will support this verb so if its not supported then a message is just sent as Plain text. TLS relies on PKI certificates and the administrative issue s that come around certificate management like expired certificates which is why ...
All sample scripts and source code is provided by for illustrative purposes only. All examples are untested in different environments and therefore, I cannot guarantee or imply reliability, serviceability, or function of these programs.

All code contained herein is provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.