MS Exchange Server allows you to create email distribution lists that can be used to send emails to a group of people without entering individual email addresses. To create such lists programmatically, this article covers how to create a distribution list on MS Exchange Server in Java. Furthermore, it shows how to fetch a distribution list programmatically.
- API to Create Distribution List on MS Exchange Server
- Create an MS Exchange Distribution List
- Fetch a Distribution List from MS Exchange Server
Java API to Create Distribution List on MS Exchange Server
To create the distribution lists on MS Exchange Server, we will use Aspose.Email for Java. The API is designed to create, send, and process emails from within Java applications. Alongside, it supports working with MS Outlook and Exchange Server without writing complex code. You can either download the API or install it using the following Maven configurations.
Repository:
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
Dependency:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-email</artifactId>
<version>22.3</version>
<classifier>jdk16</classifier>
</dependency>
Create an MS Exchange Distribution List in Java
The following are the steps to create a distribution list on MS Exchange Server in Java.
- First, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- After that, create an instance of ExchangeDistributionList class.
- Set display name of list using ExchangeDistributionList.setDisplayName() method.
- 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 Java.
Fetch a Distribution List from MS Exchange Server in Java
Now, let’s see how to fetch a distribution list from MS Exchange Server programmatically in Java.
- First, connect to Exchange Server and get the instance of the EWS client into an IEWSClient object.
- After that, get distribution list into an ExchangeDistributionList array using IEWSClient.listDistributionLists() method.
- Loop through each distribution list in the array.
- Finally, 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 Java.
Get a Free API License
You can get a free temporary license to use Aspose.Email for Java without evaluation limitations.
Conclusion
In this article, you have learned how to create distribution lists on MS Exchange Server in Java. Furthermore, you have seen how to fetch MS Exchange distribution lists programmatically. In addition, you can explore the documentation to read more about Aspose.Email for Java. Also, you can post your queries to our forum.