我目前正在使用Exchange Web服务(EWS)代表我冒充的用户创建ContactGroup
...
一切都很好,这里是代码:
var email = "frank@mydomain.com";
var accountPassword = "myPassword";
var emailAccountToImpersonify = "steve@mydomain.com";
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new NetworkCredential(email, accountPassword, "mydomain.com");
service.AutodiscoverUrl(email, RedirectionUrlValidationCallback);
// Make sure the account [frank@mydomain.com] is a member of the ApplicationImpersonation admin role.
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, emailAccountToImpersonify);
// Create a new ContactGroup on behalf of [steve@mydomain.com]
ContactGroup myContactGroup = new ContactGroup(service);
myContactGroup.DisplayName = "Gazou";
myContactGroup.Members.Add(new GroupMember("user1@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user2@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user3@contoso.com"));
myContactGroup.Save();
在创建ContactGroup Gazou 之前我想做的是:
类似的东西:
ContactGroup existingContactGroup = ContactGroup.Bind(service, **ItemId**);
if (existingContactGroup != null)
{
existingContactGroup.Delete(DeleteMode.HardDelete);
}
else
{
// Create a new ContactGroup on behalf of [steve@mydomain.com]
ContactGroup myContactGroup = new ContactGroup(service);
myContactGroup.DisplayName = "Gazou";
myContactGroup.Members.Add(new GroupMember("user1@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user2@contoso.com"));
myContactGroup.Members.Add(new GroupMember("user3@contoso.com"));
myContactGroup.Save();
}
但我似乎无法知道 如何找到ContactGroup
的ItemId。
我所知道的ContactGroup
是DisplayName
Gazou
答案 0 :(得分:0)
您只需要在显示名称上搜索存储组的联系人文件夹,例如
SearchFilter sfSearch = new SearchFilter.IsEqualTo(ContactGroupSchema.DisplayName, "NameOfGroup");
FindItemsResults<Item> findCgResults = service.FindItems(WellKnownFolderName.Contacts, sfSearch, new ItemView(1));
应该这样做