Работа с рассылочными списками на Exchange Server
Работа с рассылочными списками
Aspose.Email API предоставляет возможность создания и чтения рассылочных списков с сервера Exchange. Рассылочные списки можно создать на сервере, а также к ним можно добавлять участников с помощью IEWSClient. В этой статье показано, как работать с рассылочными списками на сервере Exchange.
Создание рассылочного списка
Следующий фрагмент кода демонстрирует, как создать рассылочный список.
// 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::SharedPtr<ExchangeDistributionList> distributionList = System::MakeObject<ExchangeDistributionList>(); | |
distributionList->set_DisplayName(u"test private list"); | |
System::SharedPtr<MailAddressCollection> members = System::MakeObject<MailAddressCollection>(); | |
members->Add(u"address1@host.com"); | |
members->Add(u"address2@host.com"); | |
members->Add(u"address3@host.com"); | |
try | |
{ | |
client->CreateDistributionList(distributionList, members); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |
Получение частного рассылочного списка
Следующий фрагмент кода демонстрирует, как получить частный рассылочный список.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::ArrayPtr<System::SharedPtr<ExchangeDistributionList>> distributionLists = client->ListDistributionLists(); | |
for (System::SharedPtr<ExchangeDistributionList> distributionList : distributionLists) | |
{ | |
System::SharedPtr<MailAddressCollection> members = client->FetchDistributionList(distributionList); | |
for (auto member : System::IterateOver(members)) | |
{ | |
System::Console::WriteLine(member->get_Address()); | |
} | |
} |
Расширение публичного рассылочного списка
Следующий фрагмент кода демонстрирует, как расширить публичный рассылочный список.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<MailAddressCollection> members = client->ExpandDistributionList(System::MakeObject<MailAddress>(u"public.distribution.list@host.com")); | |
for (auto member : System::IterateOver(members)) | |
{ | |
System::Console::WriteLine(member->get_Address()); | |
} |
Добавление участников
Добавление участников в частный рассылочный список
Следующий фрагмент кода показывает, как добавить участников в частный рассылочный список.
// 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::ArrayPtr<System::SharedPtr<ExchangeDistributionList>> distributionLists = client->ListDistributionLists(); | |
System::SharedPtr<MailAddressCollection> newMembers = System::MakeObject<MailAddressCollection>(); | |
newMembers->Add(u"address4@host.com"); | |
newMembers->Add(u"address5@host.com"); | |
client->AddToDistributionList(distributionLists[0], newMembers); |
Добавление участников без перечисления
Следующий фрагмент кода показывает, как добавить участников без перечисления.
// 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::SharedPtr<ExchangeDistributionList> distributionList = System::MakeObject<ExchangeDistributionList>(); | |
distributionList->set_Id(u"list's id"); | |
distributionList->set_ChangeKey(u"list's change key"); | |
System::SharedPtr<MailAddressCollection> newMembers = System::MakeObject<MailAddressCollection>(); | |
newMembers->Add(u"address6@host.com"); | |
client->AddToDistributionList(distributionList, newMembers); |
Отправка электронной почты на частный рассылочный список
Следующий фрагмент кода демонстрирует, как отправить электронные письма на частный рассылочный список.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::ArrayPtr<System::SharedPtr<ExchangeDistributionList>> distributionLists = client->ListDistributionLists(); | |
System::SharedPtr<MailAddress> distributionListAddress = distributionLists[0]->ToMailAddress(); | |
System::SharedPtr<MailMessage> message = System::MakeObject<MailMessage>(System::MakeObject<MailAddress>(u"from@host.com"), distributionListAddress); | |
message->set_Subject(u"sendToPrivateDistributionList"); | |
client->Send(message); |
Удаление участников
Удаление участников из частного рассылочного списка
Следующий фрагмент кода демонстрирует, как удалить участников из частного рассылочного списка.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::ArrayPtr<System::SharedPtr<ExchangeDistributionList>> distributionLists = client->ListDistributionLists(); | |
System::SharedPtr<MailAddressCollection> members = client->FetchDistributionList(distributionLists[0]); | |
System::SharedPtr<MailAddressCollection> membersToDelete = System::MakeObject<MailAddressCollection>(); | |
membersToDelete->Add(members->idx_get(0)); | |
membersToDelete->Add(members->idx_get(1)); | |
client->DeleteFromDistributionList(distributionLists[0], membersToDelete); |
Удаление участников без перечисления
Следующий фрагмент кода показывает, как удалить участников без перечисления.
// 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::SharedPtr<ExchangeDistributionList> distributionList = System::MakeObject<ExchangeDistributionList>(); | |
distributionList->set_Id(u"list's id"); | |
distributionList->set_ChangeKey(u"list's change key"); | |
System::SharedPtr<MailAddressCollection> membersToDelete = System::MakeObject<MailAddressCollection>(); | |
System::SharedPtr<MailAddress> addressToDelete = System::MakeObject<MailAddress>(u"address", true); | |
//addressToDelete.Id.EWSId = "member's id"; | |
membersToDelete->Add(addressToDelete); | |
try | |
{ | |
client->AddToDistributionList(distributionList, membersToDelete); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |
Удаление частного рассылочного списка
Следующий фрагмент кода демонстрирует, как удалить частный рассылочный список.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C | |
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser()); | |
try | |
{ | |
System::ArrayPtr<System::SharedPtr<ExchangeDistributionList>> distributionLists = client->ListDistributionLists(); | |
client->DeleteDistributionList(distributionLists[0], true); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |
Удаление без перечисления
Следующий фрагмент кода показывает, как удалить без перечисления.
// 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::SharedPtr<ExchangeDistributionList> distributionList = System::MakeObject<ExchangeDistributionList>(); | |
distributionList->set_Id(u"list's id"); | |
try | |
{ | |
client->DeleteDistributionList(distributionList, true); | |
} | |
catch (System::Exception& ex) | |
{ | |
System::Console::WriteLine(ex.get_Message()); | |
} |