Working with User Configuration on Server
Managing User Configuration
Aspose.Email API can be used to manage user configuration on an Exchange Server with the EWSClient class. This class uses Exchange Web Services, which are only available in Exchange Server 2007 and later releases. In this article, we will see how to read, create, update, and delete user configurations on Exchange Server 2010. Microsoft Exchange Server 2010 Service Pack 1 is required for all the features described in this article.
A user configuration is a named set of settings that an application stores in a folder of the mailbox. It is represented by a UserConfiguration object, whose dictionary holds the settings as key-value pairs, and identified by a UserConfigurationName - the name of the configuration and the URI of the folder.
The samples in this article use these headers and namespaces:
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfiguration.h>
#include <Clients/Exchange/WebService/UserConfiguration/UserConfigurationName.h>
#include <Clients/Exchange/ExchangeMailboxInfo.h>
#include <system/collections/dictionary.h>
#include <system/object_ext.h>
using namespace System;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
All examples in this article connect to the server like this:
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://your.exchange.server/ews/Exchange.asmx", u"username", u"password", u"domain");
client->Dispose();
Reading User Configuration
To get the user configuration information of a specific folder from the Exchange Server:
- Connect to Exchange Server using IEWSClient.
- Call the GetUserConfiguration() method to get the user configuration for a folder.
- Display the user configuration properties like ID, name and dictionary items as key-value pairs.
The keys and the values of the dictionary are objects; the strings stored in it are boxed.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
try
{
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
Console::WriteLine(u"Configuration Id: " + userConfig->get_Id());
Console::WriteLine(u"Configuration Name: " + userConfig->get_UserConfigurationName()->get_Name());
Console::WriteLine(u"Key value pairs:");
for (auto entry : userConfig->get_Dictionary())
{
Console::WriteLine(ObjectExt::ToString(entry.get_Key()) + u": " + ObjectExt::ToString(entry.get_Value()));
}
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
Creating User Configurations
To create the user configuration for a specific folder on the Exchange Server:
- Connect to the Exchange Server using IEWSClient.
- Create a UserConfiguration with its name and folder and fill its dictionary.
- Call the CreateUserConfiguration() method to create the user configuration for a folder.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = MakeObject<UserConfiguration>(userConfigName);
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"value1"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key2"), ObjectExt::Box<String>(u"value2"));
userConfig->get_Dictionary()->Add(ObjectExt::Box<String>(u"key3"), ObjectExt::Box<String>(u"value3"));
try
{
client->CreateUserConfiguration(userConfig);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
Updating User Configuration
To update the user configuration for a specific folder in the Exchange Server:
- Connect to the Exchange Server using IEWSClient.
- Read the configuration with GetUserConfiguration() and change its dictionary.
- Call the UpdateUserConfiguration() method to update the user configuration for a folder.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName);
userConfig->get_Dictionary()->idx_set(ObjectExt::Box<String>(u"key1"), ObjectExt::Box<String>(u"new-value1"));
client->UpdateUserConfiguration(userConfig);
client->Dispose();
Deleting User Configuration
To delete the user configuration for a specific folder in the Exchange Server:
- Connect to the Exchange Server using IEWSClient.
- Call the DeleteUserConfiguration() method to delete the user configuration for a folder.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<UserConfigurationName> userConfigName = MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri());
try
{
client->DeleteUserConfiguration(userConfigName);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();