Read the complete article on how to create and fetch distribution lists from MS Exchange Server in Java: https://blog.aspose.com/2022/04/07/create-exchange-distribution-list-in-java/
Last active
April 7, 2022 09:47
-
-
Save aspose-com-gists/04e417c8cb38ba69570b164e89b1bbe5 to your computer and use it in GitHub Desktop.
Create Exchange Distribution List 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"); | |
// Instantiate list | |
ExchangeDistributionList distributionList = new ExchangeDistributionList(); | |
// Set display name | |
distributionList.setDisplayName("test private list"); | |
// Add members to list | |
MailAddressCollection members = new MailAddressCollection(); | |
members.add("address1@host.com"); | |
members.add("address2@host.com"); | |
members.add("address3@host.com"); | |
// Create list | |
client.createDistributionList(distributionList, members); |
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 all lists | |
ExchangeDistributionList[] distributionLists = client.listDistributionLists(); | |
// Loop through each list and fetch members | |
for (ExchangeDistributionList distributionList : distributionLists) { | |
MailAddressCollection members = client.fetchDistributionList(distributionList); | |
for (MailAddress member : (Iterable<MailAddress>) members) { | |
System.out.println(member.getAddress()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment