Trabalhando com Configuração do Usuário no Servidor
Gerenciando Configuração do Usuário
A API Aspose.Email pode ser usada para gerenciar a configuração do usuário em um Exchange Server com a classe EWSClient. Esta classe utiliza os Serviços Web do Exchange, que estão disponíveis apenas no Exchange Server 2007 e versões posteriores. Neste artigo, veremos como ler, criar, atualizar e excluir configurações de usuário no Exchange Server 2010. O Microsoft Exchange Server 2010 Service Pack 1 é necessário para todos os recursos descritos neste artigo. O seguinte trecho de código mostra como conectar ao Exchange Server 2010 em todos os exemplos deste artigo.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
ExchangeTestUser exchangeUser = ExchangeTestUser(u"https://your.exchange.server/ews/Exchange.asmx", u"username", u"password"); | |
const System::String mailboxUri = exchangeUser.MailboxUri; | |
const System::String domain = exchangeUser.Domain; | |
const System::String username = exchangeUser.Name; | |
const System::String password = exchangeUser.Password; | |
System::SharedPtr<System::Net::NetworkCredential> credentials = System::MakeObject<System::Net::NetworkCredential>(username, password, domain); | |
System::SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(mailboxUri, credentials); |
Lendo Configuração do Usuário
Para obter as informações de configuração do usuário de uma pasta específica no Exchange Server:
- Conecte-se ao Exchange Server usando IEWSClient.
- Chame o método GetUserConfiguration() para obter a configuração do usuário para uma pasta.
- Exiba as propriedades da configuração do usuário como ID, nome e itens de dicionário como pares chave-valor.
O seguinte trecho de código mostra como ler a configuração do usuário.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
System::Console::WriteLine(u"Connected to Exchange 2010"); | |
try | |
{ | |
// Get the User Configuration for Inbox folder | |
System::SharedPtr<UserConfigurationName> userConfigName = System::MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri()); | |
System::SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName); | |
System::Console::WriteLine(System::String(u"Configuration Id: ") + userConfig->get_Id()); | |
System::Console::WriteLine(System::String(u"Configuration Name: ") + userConfig->get_UserConfigurationName()->get_Name()); | |
System::Console::WriteLine(u"Key value pairs:"); | |
for (auto o : System::IterateOver(userConfig->get_Dictionary()->get_Keys())) | |
{ | |
System::String key = System::ObjectExt::Unbox<System::String>(o); | |
System::Console::WriteLine(key + u": " + System::ObjectExt::ToString(userConfig->get_Dictionary()->idx_get(o))); | |
} | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |
Criando Configurações do Usuário
Para criar a configuração do usuário para uma pasta específica no Exchange Server:
- Conecte-se ao Exchange Server usando IEWSClient.
- Chame o método CreateUserConfiguration() para criar a configuração do usuário para uma pasta.
O seguinte trecho de código mostra como criar configurações do usuário.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
System::Console::WriteLine(u"Connected to Exchange 2010"); | |
// Create the User Configuration for Inbox folder | |
System::SharedPtr<UserConfigurationName> userConfigName = System::MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri()); | |
System::SharedPtr<UserConfiguration> userConfig = System::MakeObject<UserConfiguration>(userConfigName); | |
userConfig->get_Dictionary()->Add(System::ObjectExt::Box<System::String>(u"key1"), System::ObjectExt::Box<System::String>(u"value1")); | |
userConfig->get_Dictionary()->Add(System::ObjectExt::Box<System::String>(u"key2"), System::ObjectExt::Box<System::String>(u"value2")); | |
userConfig->get_Dictionary()->Add(System::ObjectExt::Box<System::String>(u"key3"), System::ObjectExt::Box<System::String>(u"value3")); | |
try | |
{ | |
client->CreateUserConfiguration(userConfig); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |
Atualizando Configuração do Usuário
Para atualizar a configuração do usuário para uma pasta específica no Exchange Server:
- Conecte-se ao Exchange Server usando IEWSClient.
- Chame o método UpdateUserConfiguration() para atualizar a configuração do usuário para uma pasta.
O seguinte trecho de código mostra como atualizar a configuração do usuário.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(); | |
System::Console::WriteLine(u"Connected to Exchange 2010"); | |
// Create the User Configuration for Inbox folder | |
System::SharedPtr<UserConfigurationName> userConfigName = System::MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri()); | |
System::SharedPtr<UserConfiguration> userConfig = client->GetUserConfiguration(userConfigName); | |
userConfig->set_Id(nullptr); | |
// Update User Configuration | |
userConfig->get_Dictionary()->idx_set(System::ObjectExt::Box<System::String>(u"key1"), System::ObjectExt::Box<System::String>(u"new-value1")); | |
client->UpdateUserConfiguration(userConfig); |
Excluindo Configuração do Usuário
Para excluir a configuração do usuário para uma pasta específica no Exchange Server:
- Conecte-se ao Exchange Server usando IEWSClient.
- Chame o método DeleteUserConfiguration() para excluir a configuração do usuário para uma pasta.
O seguinte trecho de código mostra como excluir a configuração do usuário.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<System::Net::NetworkCredential> credentials = System::MakeObject<System::Net::NetworkCredential>(username, password, domain); | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
System::Console::WriteLine(u"Connected to Exchange 2010"); | |
// Delete User Configuration | |
System::SharedPtr<UserConfigurationName> userConfigName = System::MakeObject<UserConfigurationName>(u"inbox.config", client->get_MailboxInfo()->get_InboxUri()); | |
try | |
{ | |
client->DeleteUserConfiguration(userConfigName); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |