0

我想从 Outlook 中返回一个姓名和电子邮件地址列表,并将它们填充到一个列表框中,以便我可以选择我想要的那些。

我希望从用户本地联系人列表以及交换服务器上的全局地址列表中执行此操作。

我看过很多例子(下),但没有任何效果,所以任何帮助都会受到欢迎。

谢谢

格雷厄姆

我在用

Imports Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Interop

对于这两个例子:

 Dim itemx As ListViewItem

        'Create an Outlook application.
        Dim oApp As Outlook._Application = New Outlook.Application()

        ' Get the MAPI namespace.
        Dim oNS As Outlook.NameSpace = oApp.Session
        ' Get the Global Address List.
        Dim oALs As Outlook.AddressLists = oNS.AddressLists
        Dim oGal As Outlook.AddressList = oALs.Item("Global Address List")

        ' Get all the entries.
        Dim oEntries As Outlook.AddressEntries = oGal.AddressEntries
        ' Get the first user.
        Dim oEntry As Outlook.AddressEntry = oEntries.GetFirst

        For i As Long = 1 To 10 ' Cut down to 100 as I dont want to load the full AB ** Need to Search rather than Loop **
            If oEntries(i).DisplayType = Outlook.OlDisplayType.olUser Then
                itemx = ListView1.Items.Add(oEntries(i).Name)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.JobTitle)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.BusinessTelephoneNumber)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.OfficeLocation)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.PrimarySmtpAddress)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.CompanyName)
                itemx.SubItems.Add(oEntries(i).GetExchangeUser.Alias)
            End If
        Next

        ' Clean up.
        oApp = Nothing
        oNS = Nothing
        oALs = Nothing
        oGal = Nothing
        oEntries = Nothing
        oEntry = Nothing

也试过:

' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
'Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
'oNS.Logon("Outlook", , False, True) ' TODO:
oNS.Logon("Outlook", Nothing, False, True)
' Get the first contact from the Contacts folder.
Dim cContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim oItems As Outlook.Items = cContacts.Items
Dim oCt As Outlook.ContactItem

Try
  oCt = oItems.GetFirst()
  ' Display some common properties.
  ListBox1.Items.Add(oCt.FullName)
  ListBox1.Items.Add(oCt.Title)
  ListBox1.Items.Add(oCt.Birthday)
  ListBox1.Items.Add(oCt.CompanyName)
  ListBox1.Items.Add(oCt.Department)
  ListBox1.Items.Add(oCt.Body)
  ListBox1.Items.Add(oCt.FileAs)
  ListBox1.Items.Add(oCt.Email1Address)
  ListBox1.Items.Add(oCt.BusinessHomePage)
  ListBox1.Items.Add(oCt.MailingAddress)
  ListBox1.Items.Add(oCt.BusinessAddress)
  ListBox1.Items.Add(oCt.OfficeLocation)
  ListBox1.Items.Add(oCt.Subject)
  ListBox1.Items.Add(oCt.JobTitle)
  Catch
      ListBox1.Items.Add("an error occurred")
     'Finally

     ' Display
     'oCt.Display(True)
     ' Log off.
     oNS.Logoff()
    ' Clean up.
     oApp = Nothing
     oNS = Nothing
     oItems = Nothing
     oCt = Nothing
  End Try
4

3 回答 3

0

您的第一个示例中的示例代码似乎是正确的,但“全局地址列表”访问字符串除外。尝试使用 1 作为数组索引:

Dim oGal As AddressList = oALs.Item(1)

我可以通过这样做访问我的联系人。

于 2014-06-26T00:10:58.477 回答
0

Dim oGal As AddressList = oALs.Item(x) // <-- x 代表每个文件夹、全局、联系人、公共等

于 2015-07-16T16:12:20.683 回答
0

这对我有用:

 Dim oGal As Outlook.AddressList = oNS.GetGlobalAddressList
于 2015-11-12T18:18:49.617 回答