Read the complete article on how to add or remove members from MS Exchange Distribution lists in C# .NET: https://blog.aspose.com/2022/04/07/manage-members-in-exchange-distribution-list-in-csharp/
Last active
April 8, 2022 04:26
-
-
Save aspose-com-gists/d2e7147cd939cf4f09e6d5f5626d1b38 to your computer and use it in GitHub Desktop.
Add and Remove Members from MS Exchange Distribution Lists in C#
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 distribution lists | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
// Create a new list and add members | |
MailAddressCollection newMembers = new MailAddressCollection(); | |
newMembers.Add("address4@host.com"); | |
newMembers.Add("address5@host.com"); | |
// Merge members to 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 all distribution lists | |
ExchangeDistributionList[] distributionLists = client.ListDistributionLists(); | |
// Fetch members from a specific list | |
MailAddressCollection members = client.FetchDistributionList(distributionLists[0]); | |
// Create a new list and add members to be deleted | |
MailAddressCollection membersToDelete = new MailAddressCollection(); | |
membersToDelete.Add(members[0]); | |
membersToDelete.Add(members[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