Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 7, 2022 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/04e417c8cb38ba69570b164e89b1bbe5 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/04e417c8cb38ba69570b164e89b1bbe5 to your computer and use it in GitHub Desktop.
Create Exchange Distribution List in Java
// 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);
// 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