将outlook中的姓名和电子邮件地址列表返回到vb.net列表框
我想从outlook返回一个姓名和电子邮件地址的列表,并将它们填充到列表框中,以便我可以选择我想要的 我希望从exchange服务器上的用户本地联系人列表和全局地址列表中执行此操作 我在下面看到了很多例子,但都不管用,所以任何帮助都是非常受欢迎的 谢谢 格雷厄姆 我正在使用将outlook中的姓名和电子邮件地址列表返回到vb.net列表框,vb.net,email,outlook,vb.net-2010,import-contacts,Vb.net,Email,Outlook,Vb.net 2010,Import Contacts,我想从outlook返回一个姓名和电子邮件地址的列表,并将它们填充到列表框中,以便我可以选择我想要的 我希望从exchange服务器上的用户本地联系人列表和全局地址列表中执行此操作 我在下面看到了很多例子,但都不管用,所以任何帮助都是非常受欢迎的 谢谢 格雷厄姆 我正在使用 Imports Microsoft.Office.Interop.Outlook Imports Microsoft.Office.Interop 对于这两个示例: Dim itemx As ListViewItem
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
第一个示例中的示例代码似乎是正确的,但全局地址列表访问字符串除外。尝试使用1作为数组索引:
Dim oGal As AddressList = oALs.Item(1)
通过这样做,我可以访问我的联系人。Dim oGal As AddressList=oALs.Itemx/这对我很有用:
Dim oGal As Outlook.AddressList = oNS.GetGlobalAddressList
请展示你目前所拥有的。此外,如果您不是从VSTO加载项运行Outlook对象模型保护,并使用通过该基础结构提供的对应用程序对象的引用,则Outlook对象模型保护也会遇到问题。它不必是VSTO加载项。任何COM加载项都是可信的。您还可以使用扩展的MAPI C++或Delphi或任何语言的兑换来避免安全提示。编辑后的帖子显示代码,VSTO也是什么?是的,是工作的接缝,由于代码限制返回条目的数量为10条,我如何获取返回条目的数量?我如何获取我的个人联系人列表而不是全局地址列表?我不太确定返回条目的数量是什么意思。。?你想知道总共有多少人吗?尝试输入。计数或输入。长度