Read the complete article on how to add and remove members in MS Exchange distribution lists in Java: https://blog.aspose.com/2022/03/07/manage-members-in-exchange-distribution-lists-in-java/
Last active
April 8, 2022 09:58
-
-
Save aspose-com-gists/32ba9a85096bf605d5f239a882cf057b to your computer and use it in GitHub Desktop.
Add and Remove Members in MS Exchange Distribution Lists in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect to Exchange Server | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get lists | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
// Create a new list and add members to be added | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.add("address4@host.com"); | |
newMembers.add("address5@host.com"); | |
// Add new list to existing list | |
client.addToDistributionList(distributionLists[0], newMembers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Connect to Exchange Server | |
IEWSClient client = EWSClient.getEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get lists | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
// Fetch members of desired list | |
MailAddressCollection members = client.fetchDistributionList(distributionLists[0]); | |
// Create a new list and add members to be deleted | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.addMailAddress(members.get_Item(0)); | |
membersToDelete.addMailAddress(members.get_Item(1)); | |
// Delete members | |
client.deleteFromDistributionList(distributionLists[0], membersToDelete); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment