我想从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
答案 0 :(得分:0)
第一个示例中的示例代码似乎是正确的,除了"全局地址列表"访问字符串。尝试使用1作为数组索引:
Dim oGal As AddressList = oALs.Item(1)
通过这样做,我能够访问我的联系人。
答案 1 :(得分:0)
Dim oGal As AddressList = oALs.Item(x)//< - x代表每个文件夹,global,contacts,public,ect
答案 2 :(得分:0)
这对我有用:
Dim oGal As Outlook.AddressList = oNS.GetGlobalAddressList