elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Trabajando con las ramas de git (tercera parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Pasar contactos de correo Outlook a tabla vb.net
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Pasar contactos de correo Outlook a tabla vb.net  (Leído 1,698 veces)
eotinianor

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Pasar contactos de correo Outlook a tabla vb.net
« 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


En línea

eotinianor

Desconectado Desconectado

Mensajes: 5


Ver Perfil
Re: Pasar contactos de correo Outlook a tabla vb.net
« Respuesta #1 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


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines