MS Exchange Server allows you to create distribution lists to send emails to a group of people. In the previous article, we have covered how to create or fetch Exchange distribution lists in Java. In this article, you will learn how to add or remove members in MS Exchange distribution lists in Java.
- Java API to Manage Members of Exchange Distribution Lists
- Add Members to MS Exchange Distribution Lists
- Remove Members from MS Exchange Distribution Lists
Java API to Manage Members of Exchange Distribution Lists
To work with members of distribution lists on MS Exchange Server, we will use Aspose.Email for Java. It is a powerful API that allows you to work with MS Exchange Server seamlessly. 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>
Add Members to MS Exchange Distribution Lists in Java
The following are the steps to add members to MS Exchange distribution list in Java.
- 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 Java.
Remove Members from MS Exchange Distribution Lists in Java
The following are the steps to remove members from MS Exchange distribution list using Java.
- 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 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, we have covered how to manipulate members in MS Exchange distribution lists programmatically. With the help of code samples, you have seen how to add or remove members from an Exchange distribution list in Java. Alongside, you can explore the documentation to read more about Aspose.Email for Java. Also, you can ask your questions via our forum.