Exchange Server'da Kurallarla Çalışma
Kuralları Yönetme
Aspose.Email, Exchange Server üzerindeki kuralları yönetmek için kullanılabilir EWSClient sınıfı. Bu sınıf Exchange Web Services (EWS) kullanır; bu hizmetler Exchange Server 2007 ve sonraki sürümlerde mevcuttur. Kuralları nasıl yöneteceğinizi göstermek için bu makale şu adımları açıklar:
- Sunucuda zaten bulunan kuralları oku.
- Yeni bir kural oluştur.
- Mevcut bir kuralı güncelle.
Bu makalede anlatılan tüm özellikler için Microsoft Exchange Server 2010 Service Pack 1 gereklidir.
Bir kural şu şekilde temsil edilir: InboxRule nesnedir. Koşulları bir RulePredicates nesne - örneğin göndericiler veya konunun içermesi gereken kelimeler - ve eylemleri bir RuleActions nesne - örneğin mesajın taşınacağı klasör.
Bu makaledeki örnekler şu başlıkları ve ad alanlarını kullanır:
#include <MailAddress.h>
#include <MailAddressCollection.h>
#include <Clients/Exchange/WebService/EWSClient/EWSClient.h>
#include <Clients/Exchange/WebService/EWSClient/IEWSClient.h>
#include <Clients/Exchange/InboxRules/InboxRule.h>
#include <Clients/Exchange/InboxRules/RulePredicates.h>
#include <Clients/Exchange/InboxRules/RuleActions.h>
#include <system/array.h>
#include <system/collections/specialized/string_collection.h>
using namespace System;
using namespace Aspose::Email;
using namespace Aspose::Email::Clients::Exchange;
using namespace Aspose::Email::Clients::Exchange::WebService;
Kuralları Oku
Exchange Server’dan tüm kuralları almak için:
- Exchange Sunucusuna bağlanmak için IEWSClient sınıf.
- Şuğu çağırın IEWSClient->GetInboxRules() tüm kuralları almak için yöntem.
- Bir döngü içinde tüm kurallara göz atıp koşullar, eylemler ve isimler gibi kural özelliklerini gösterin.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
try
{
for (SharedPtr<InboxRule> inboxRule : client->GetInboxRules())
{
Console::WriteLine(u"Display Name: " + inboxRule->get_DisplayName());
// The "From Address" condition
for (SharedPtr<MailAddress> fromAddress : inboxRule->get_Conditions()->get_FromAddresses())
{
Console::WriteLine(u"From: " + fromAddress->get_DisplayName() + u" - " + fromAddress->get_Address());
}
// The "Subject Contains" condition
SharedPtr<Collections::Specialized::StringCollection> subjectStrings = inboxRule->get_Conditions()->get_ContainsSubjectStrings();
for (int32_t i = 0; i < subjectStrings->get_Count(); i++)
{
Console::WriteLine(u"Subject contains: " + subjectStrings->idx_get(i));
}
// The "Move to Folder" action
if (!String::IsNullOrEmpty(inboxRule->get_Actions()->get_MoveToFolder()))
{
Console::WriteLine(u"Move message to folder: " + inboxRule->get_Actions()->get_MoveToFolder());
}
}
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
Yeni Kural Oluşturma
Exchange Server’da yeni bir kural oluşturmak için aşağıdaki adımları izleyin:
- Exchange Sunucusuna bağlanmak için IEWSClient sınıf.
- Yeni bir … örneği oluşturun InboxRule sınıfı ve aşağıdaki zorunlu özellikleri ayarlayın:
- GörünümAdı
- Koşullar
- Eylemler
- Şuğu çağırın IEWSClient->CreateInboxRule() kural oluşturmak için yöntem.
Aşağıdaki kural, konusuna "ABC" içeren belirli bir göndericiden gelen mesajları başka bir klasöre taşır. Klasör, istemci tarafından döndürülen klasör bilgilerinin bir parçası olan kimliğiyle tanımlanır. İkinci argüman MailAddress yapıcı, true, adresin sözdizim kontrolünü atlar.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
SharedPtr<InboxRule> rule = MakeObject<InboxRule>();
rule->set_DisplayName(u"Message from client ABC");
// Conditions: the subject contains "ABC" and the message comes from the given sender
SharedPtr<RulePredicates> conditions = MakeObject<RulePredicates>();
conditions->get_ContainsSubjectStrings()->Add(u"ABC");
conditions->get_FromAddresses()->Add(MakeObject<MailAddress>(u"administrator@ex2010.local", true));
rule->set_Conditions(conditions);
// Action: move the message to a folder
SharedPtr<RuleActions> actions = MakeObject<RuleActions>();
actions->set_MoveToFolder(u"120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA==");
rule->set_Actions(actions);
try
{
client->CreateInboxRule(rule);
}
catch (System::Exception& ex)
{
Console::WriteLine(ex->get_Message());
}
client->Dispose();
Kuralı Güncelleme
Exchange Server’da bir kuralı güncellemek için:
- Exchange Sunucusuna bağlanmak için IEWSClient sınıf.
- Şuğu çağırın IEWSClient->GetInboxRules() tüm kuralları almak için yöntem.
- Bir döngü içinde tüm kuralları tarayın ve değiştirmek istediğiniz kuralı görüntü adıyla bulun.
- Kural özelliklerini güncelle.
- Şuğu çağırın IEWSClient->UpdateInboxRule() kuralı güncellemek için yöntem.
Örnek, yukarıda oluşturulan kuralın ilk gönderici adresini değiştirir.
SharedPtr<IEWSClient> client = EWSClient::GetEWSClient(u"https://outlook.office365.com/ews/exchange.asmx", u"username", u"password");
for (SharedPtr<InboxRule> inboxRule : client->GetInboxRules())
{
Console::WriteLine(u"Display Name: " + inboxRule->get_DisplayName());
if (inboxRule->get_DisplayName() == u"Message from client ABC")
{
Console::WriteLine(u"Updating the rule....");
inboxRule->get_Conditions()->get_FromAddresses()->idx_set(0, MakeObject<MailAddress>(u"administrator@ex2010.local", true));
client->UpdateInboxRule(inboxRule);
}
}
client->Dispose();