使用Exchange Web Services (EWS)来操作Distribution Group的成员。EWS是基于SOAP开发的Web Services,可以通过其提供的API来访问和操作Exchange Server中的对象和数据。在EWS中,可以使用以下示例代码来添加或删除Distribution Group的成员:
//添加成员:
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials("username", "password");
service.Url = new Uri("https://mail.contoso.com/EWS/Exchange.asmx"); //Exchange服务器的URL
//创建Distribution Group成员的EmailAddress对象
EmailAddress member = new EmailAddress("member1@contoso.com");
//在Distribution Group中添加成员
DistributionGroup dg = DistributionGroup.Bind(service, new
FolderId(WellKnownFolderName.Contacts, mailbox));
dg.Members.Add(member);
dg.Update(ConflictResolutionMode.AlwaysOverwrite);
//删除成员:
DistributionGroup dg = DistributionGroup.Bind(service, new
FolderId(WellKnownFolderName.Contacts, mailbox));
dg.Members.Remove("member1@contoso.com");
dg.Update(ConflictResolutionMode.AlwaysOverwrite);
其中,username
和password
分别为Exchange Server的登录用户名和密码,https://mail.contoso.com/EWS/Exchange.asmx
为Exchange Server的Web Services URL,mailbox
为电子邮件地址,可以是用户的SMTP地址或公开的邮件文件夹的路径。