我有两个问题
我想将电子邮件联系人添加到Exchange服务器。我已经看到了使用EWS的示例代码。但该代码用于添加用户特定的联系人。如何添加特定的联系人域。
我想从Exchange服务器获取域名联系人。我不希望所有联系人只需要今天添加或修改的联系人。
我怎样才能实现这一点。任何人都可以帮助我吗?
此致 Vairamuthu.G.S
答案 0 :(得分:1)
我不明白“特定于联系人网域”,但我会与您分享我的代码。这可能会有所帮助
添加联系人
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// you should set the credentials of the user and
//call AutoDiscover to get the service URL before executing the code
Contact newcontact = new Contact(service);
newcontact.DisplayName = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress();
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Address = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Name = newcontact.DisplayName;
newcontact.FileAs = newcontact.DisplayName;
newcontact.Save();
请注意,新联系人将保存在登录用户的邮箱的“联系人”文件夹中。
过滤检索到的联系人
SearchFilter filter = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeCreated, DateTime.Now.AddDays(-1));
FindItemsResults<Item> contactCreatedToday = service.FindItems(WellKnownFolderName.Contacts, filter, new ItemView(int.MaxValue));
foreach (Item t in contactCreatedToday)
{
try
{
Contact c = (Contact) t;
//do processing
}
catch (InvalidCastException)
{
throw;
}
}