Read the complete article on how to create and fetch distribution lists from MS Exchange Server in C#: https://blog.aspose.com/2022/03/06/create-exchange-distribution-list-in-csharp/
Last active
April 6, 2022 18:08
-
-
Save aspose-com-gists/5dcd8815c04f506f518ca26c77afd0d0 to your computer and use it in GitHub Desktop.
Create Exchange Distribution List in C# .NET
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"); | |
// 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); |
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"); | |
// 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