Работа с рассылками на сервере Exchange
Работа с рассылками
API Aspose.Email предоставляет возможность создавать и читать рассылки с сервера Exchange. Рассылки могут быть созданы на сервере, а также к ним могут быть добавлены участники с использованием IEWSClient. В этой статье показано, как работать с рассылками на сервере Exchange.
Создание рассылки
Следующий фрагмент кода показывает, как создать рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.DisplayName = "test private list"; | |
MailAddressCollection members = new MailAddressCollection(); | |
members.Add("address1@host.com"); | |
members.Add("address2@host.com"); | |
members.Add("address3@host.com"); | |
client.CreateDistributionList(distributionList, members); |
Получение приватной рассылки
Следующий фрагмент кода показывает, как получить приватную рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
foreach (ExchangeDistributionList distributionList in distributionLists) | |
{ | |
MailAddressCollection members = client.FetchDistributionList(distributionList); | |
foreach (MailAddress member in members) | |
{ | |
Console.WriteLine(member.Address); | |
} | |
} |
Создание MailAddress из Id рассылки
Следующий фрагмент кода показывает, как создать MailAddress из Id рассылки.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
String id = distributionLists[0].Id; | |
MailAddress distributionListAddress = new MailAddress("privateDL", true); | |
distributionListAddress.Id.EWSId = id; |
Расширение публичной рассылки
Следующий фрагмент кода показывает, как расширить публичную рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
MailAddressCollection members = client.ExpandDistributionList(new MailAddress("public.distribution.list@host.com")); | |
foreach (MailAddress member in members) | |
{ | |
Console.WriteLine(member.Address); | |
} |
Добавление участников
Добавление участников в приватную рассылку
Следующий фрагмент кода показывает, как добавить участников в приватную рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address4@host.com"); | |
newMembers.Add("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-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address6@host.com"); | |
client.AddToDistributionList(distributionList, newMembers); |
Отправка на приватную рассылку
Следующий фрагмент кода показывает, как отправить сообщение на приватную рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddress distributionListAddress = distributionLists[0].ToMailAddress(); | |
MailMessage message = new MailMessage(new MailAddress("from@host.com"), distributionListAddress); | |
message.Subject = "sendToPrivateDistributionList"; | |
client.Send(message); |
Удаление участников
Удаление участников из приватной рассылки
Следующий фрагмент кода показывает, как удалить участников из приватной рассылки.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
MailAddressCollection members = client.FetchDistributionList(distributionLists[0]); | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.Add(members[0]); | |
membersToDelete.Add(members[1]); | |
client.DeleteFromDistributionList(distributionLists[0], membersToDelete); |
Удаление участников без списка
Следующий фрагмент кода показывает, как удалить участников без списка.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
distributionList.ChangeKey = "list's change key"; | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
MailAddress addressToDelete = new MailAddress("address", true); | |
//addressToDelete.Id.EWSId = "member's id"; | |
membersToDelete.Add(addressToDelete); | |
client.AddToDistributionList(distributionList, membersToDelete); |
Удаление приватной рассылки
Следующий фрагмент кода показывает, как удалить приватную рассылку.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
client.DeleteDistributionList(distributionLists[0],true); |
Удаление без списка
Следующий фрагмент кода показывает, как удалить без списка.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
distributionList.Id = "list's id"; | |
client.DeleteDistributionList(distributionList,true); |