我正在尝试显示 Outlook 帐户的联系人列表。(Outlook 2016)以下代码显示全局联系人列表,但不显示您自己的个人联系人列表。如何显示帐户地址列表?这是我到目前为止的代码:
try
{
Outlook._Application application = new Outlook.Application();
Outlook.AddressList addrList = null;
foreach (Outlook.AddressList oAL in application.Session.AddressLists)
{
Outlook.MAPIFolder folder = oAL.GetContactsFolder();
}
Outlook.SelectNamesDialog dlg = application.Session.GetSelectNamesDialog();
dlg.InitialAddressList = addrList;
dlg.ShowOnlyInitialAddressList = true;
dlg.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo;
dlg.Display();
if (dlg.Recipients.Count > 0)
{
foreach (Outlook.Recipient recip in dlg.Recipients)
{
Outlook.PropertyAccessor pa = recip.PropertyAccessor;
string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
AddrTextBox.Text += smtpAddress;
AddrTextBox.Text += "; ";
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}