MS Exchange Server provides the feature of creating distribution lists or groups. These distribution lists allow you to send emails to a group of people without requiring you to enter individual email addresses. In this article, you will learn how to create a distribution list on MS Exchange Server in C# .NET. Furthermore, we will cover how to fetch a distribution list programmatically.
- .NET API to Create Distribution List on MS Exchange Server
- Create an MS Exchange Distribution List
- Fetch a Distribution List from MS Exchange Server
C# .NET API to Create Distribution List on MS Exchange Server
To create the distribution lists on MS Exchange Server, we will use Aspose.Email for .NET. It is a powerful API to create, send, and process emails from within .NET applications. In addition, it allows you to work with MS Outlook and Exchange Server seamlessly. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Create an MS Exchange Distribution List in C#
The following are the steps to create a distribution list on MS Exchange Server in C#.
- First, specify the network credentials.
- Then, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- Create an instance of ExchangeDistributionList class.
- Set display name of list using ExchangeDistributionList.DisplayName property.
- Create an instance of MailAddressCollection class and add members to the collection.
- Finally, create distribution list using IEWSClient.CreateDistributionList(ExchangeDistributionList, MailAddressCollection) method.
The following code sample shows how to create an MS Exchange distribution list in C#.
Fetch a Distribution List from MS Exchange Server in C#
Now, let’s see how to fetch a distribution list from MS Exchange Server programmatically in C#.
- Specify the network credentials.
- Connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- Get distribution list into an ExchangeDistributionList array using IEWSClient.ListDistributionLists() method.
- Loop through each distribution list in the array.
- Use IEWSClient.FetchDistributionList(ExchangeDistributionList) method to fetch the members of the distribution list.
The following code sample shows how to fetch distribution lists from MS Exchange Server in C#.
Get a Free API License
You can get a free temporary license to use Aspose.Email for .NET without evaluation limitations.
In this article, you have learned how to create distribution lists on MS Exchange Server in C#. Furthermore, you have seen how to fetch MS Exchange distribution lists programmatically. Besides, you can read about other features of Aspose.Email for .NET from the documentation. Also, you can post your queries to our forum.