Título: Pasar contactos de correo Outlook a tabla vb.net Publicado por: eotinianor en 27 Septiembre 2019, 16:36 pm Hice esto:
Dim dtCorreos As New DataTable Dim dr As DataRow With dtCorreos .Columns.Add("Correo", Type.GetType("System.String")) End With Try 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("Lista global de direcciones") ' Get all the entries. Dim oEntries As Outlook.AddressEntries = oGal.AddressEntries Dim Mail As String Dim nUsuarios As Integer = oEntries.Count For i As Integer = 1 To nUsuarios Mail = oEntries(i).GetExchangeUser.PrimarySmtpAddress.ToString With dtCorreos dr = .NewRow 'dr("ID") = i dr("Correo") = Mail .Rows.Add(dr) End With Next oApp = Nothing oNS = Nothing oALs = Nothing oGal = Nothing oEntries = Nothing Return True Catch ex As System.Exception MessageBox.Show("Error verificando mail") Return False End Try Para pasar los contactos de outlook a una tabla vb.net. Me jala un solo contacto, en el segundo valor del for me sale error al asignar la variable Mail Ese código lo copié de un ejemplo en internet y lo adapte a mi caso Si alguien puede ayudarme a detectar el error y corregirlo, le estaré muy agradecido Título: Re: Pasar contactos de correo Outlook a tabla vb.net Publicado por: eotinianor en 27 Septiembre 2019, 22:26 pm Para los que aún tienen el mismo problema logré solucionarlo así:
Dim Correos As ArrayList = New ArrayList() Try Dim oApp As Outlook._Application = New Outlook.Application() Dim oNS As Outlook.NameSpace = oApp.Session Dim oALs As Outlook.AddressLists = oNS.AddressLists Dim oGal As Outlook.AddressList = oALs.Item("Lista global de direcciones") Dim UsuarioExchange As Outlook.ExchangeUser Dim Mail As String For Each oEntries As Outlook.AddressEntry In oGal.AddressEntries If oEntries.AddressEntryUserType = OlAddressEntryUserType.olExchangeUserAddressEntry Then UsuarioExchange = oEntries.GetExchangeUser Mail = UsuarioExchange.PrimarySmtpAddress.ToString Correos.Add(Mail) End If Next oApp = Nothing oNS = Nothing oALs = Nothing oGal = Nothing UsuarioExchange = Nothing Catch ex As System.Exception MessageBox.Show("Error al acceder a la Lista global de direcciones del correo Outlook") End Try Agregué un if para controlar que en la variable UsuarioExchange se cargue un usuario válido de exchange y lo cargo en un arreglo, ya no en una tabla, para que el proceso de búsqueda que hago después se procese más rápido |