Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 6, 2022 18:08
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/5dcd8815c04f506f518ca26c77afd0d0 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/5dcd8815c04f506f518ca26c77afd0d0 to your computer and use it in GitHub Desktop.
Create Exchange Distribution List in C# .NET
// Connect to Exchange Server
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
// Create a list and set name
ExchangeDistributionList distributionList = new ExchangeDistributionList();
distributionList.DisplayName = "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 on Exchange Server
client.CreateDistributionList(distributionList, members);
// Connect to Exchange Server
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
// Fetch lists
ExchangeDistributionList[] distributionLists = client.ListDistributionLists();
// Loop through lists and their members
foreach (ExchangeDistributionList distributionList in distributionLists)
{
MailAddressCollection members = client.FetchDistributionList(distributionList);
foreach (MailAddress member in members)
{
Console.WriteLine(member.Address);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment