【发布时间】:2016-02-22 08:59:05
【问题描述】:
您好,我尝试为一个俱乐部编写一个应用程序,让年长的会员更容易使用 Outlook 和发送电子邮件。只是一种友好的方式,让老年人可以轻松地在屏幕上书写和查看内容。但我是一名新手程序员,以前从未使用过 EWS 托管 API。我想要的是将全局地址列表同步到我的程序,这样我就可以将它们分配给一个对象并做更多的事情。但是我已经没有任何线索了。
我尝试了什么:
对于我自己的本地联系人列表(作品)
private void AsignValuetoClass(object sender, RoutedEventArgs e)
{
//For the connection
es.UseDefaultCredentials = true;
es.AutodiscoverUrl("max.mustermann@muster.at", RedirectionUrlValidationCallback);
//How many Contacts are in the folder
ContactsFolder contactsfolder = ContactsFolder.Bind(es, WellKnownFolderName.Contacts);
//To get a specific number of contacts
int numItems = contactsfolder.TotalCount < 50 ? contactsfolder.TotalCount : 50;
//object of the Itemview
ItemView view = new ItemView(numItems);
//return the stuff
FindItemsResults<Item> contactIds = es.FindItems(WellKnownFolderName.Contacts, view);
//loop throug the item
foreach (Item item in contactIds)
{
if (item is Contact)
{
//assign of the contact items
Contact contact = item as Contact;
//new list
List<Contact> testlist = new List<Contact>();
//Add the contacts
testlist.Add(contact);
//loop through contact list
foreach (Contact Liste in testlist)
{
//new object on every run
TestKlasse test = new TestKlasse();
//assign
test.id = Convert.ToString(contact.Id);
test.Vorname = contact.GivenName;
test.Nachname = contact.Surname;
}
Console.WriteLine("Some stupid Text");
}
}
}
从 GAL 获取联系人(不工作)。
private void SearchContacts(object sender, EventArgs e)
{
//For the connection
es.UseDefaultCredentials = true;
es.AutodiscoverUrl("max.mustermann@muster.at", RedirectionUrlValidationCallback);
NameResolutionCollection nameResolutions = es.ResolveName(
"Contacts",
ResolveNameSearchLocation.DirectoryThenContacts,
true);
foreach (NameResolution nameResolution in nameResolutions)
{
ExpandGroupResults groupResults = es.ExpandGroup(nameResolution.Mailbox.Address);
foreach (EmailAddress member in groupResults.Members)
{
Console.WriteLine(member.Name + " <" + member.Address + ">");
}
}
}
我也尝试了 resolvename() 的东西,但它只适用于一个联系人或匹配的联系人。我需要每个联系人。这是代码: 私人无效搜索联系人(对象发送者,EventArgs e) {
//For the connection
es.UseDefaultCredentials = true;
es.AutodiscoverUrl("max.mustermann@muster.at", RedirectionUrlValidationCallback);
// Identify the mailbox folders to search for potential name resolution matches.
List<FolderId> folders = new List<FolderId>() { new FolderId(WellKnownFolderName.Contacts) };
// Search for all contact entries in the default mailbox contacts folder and in Active Directory Domain Services (AD DS). This results in a call to EWS.
NameResolutionCollection coll = es.ResolveName("Anderl", folders, ResolveNameSearchLocation.ContactsThenDirectory, false);
foreach (NameResolution nameRes in coll)
{
Console.WriteLine("Contact name: " + nameRes.Mailbox.Name);
Console.WriteLine("Contact e-mail address: " + nameRes.Mailbox.Address);
Console.WriteLine("Mailbox type: " + nameRes.Mailbox.MailboxType);
}
}
任何帮助都会很棒,感谢您的时间。对不起我的英语不好。
【问题讨论】:
-
无法使用 EWS 获取整个 GAL。您只能从 GAL 中检索前 100 个用户或搜索特定用户。看到这个答案:stackoverflow.com/questions/28057759/…
-
哦,好的,感谢您在谷歌上找到的信息,但现在没有运气了。
标签: c# wpf ews-managed-api