While working with MS Exchange Server from within .NET applications, you may need to work with distribution lists. In the previous post, you have seen how to create and fetch Exchange distribution lists. In this article, you will learn how to add or remove members in Exchange distribution lists in C#.
- .NET API to Add and Remove Members of Exchange Distribution Lists
- Add Members to MS Exchange Distribution Lists
- Remove Members from MS Exchange Distribution Lists
C# API to Add and Remove Members of Exchange Distribution Lists
To work with members of distribution lists on MS Exchange Server, we will use Aspose.Email for .NET. It is a well-known API to create email client applications and work with MS Exchange Server. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Add Members to MS Exchange Distribution Lists in C#
The following are the steps to add members to MS Exchange distribution list in C# .NET.
- First, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- Then, get distribution lists into an ExchangeDistributionList array using IEWSClient.ListDistributionLists() method.
- After that, create an instance of MailAddressCollection class and add members to the collection.
- Finally, add members to the specific distribution list using IEWSClient.AddToDistributionList(ExchangeDistributionList, MailAddressCollection) method.
The following code sample shows how to add members to an Exchange distribution list in C#.
C# Remove Members from MS Exchange Distribution Lists
The following are the steps to remove members from MS Exchange distribution list using C# .NET.
- First, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- Then, get distribution lists into an ExchangeDistributionList array using IEWSClient.ListDistributionLists() method.
- After that, get the reference of a particular list using IEWSClient.FetchDistributionList(ExchangeDistributionList) method.
- Then, create an instance of MailAddressCollection class and add members to be deleted.
- Finally, delete members from distribution list using IEWSClient.DeleteFromDistributionList(ExchangeDistributionList, MailAddressCollection) method.
The following code sample shows how to delete members from Exchange distribution lists in C#.
C# API to Work with Exchange Distribution List - Get a Free License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
Conclusion
In this article, you have learned how to manage members in distribution lists on Microsoft Exchange Server. Particularly, you have seen how to add or remove members from Exchange distribution lists programmatically in C#. Alongside, you can explore the documentation to read more about Aspose.Email for .NET. Also, you can ask your questions via our forum.