Visual Basic.NET - Pasar contactos de Outlook a tabla vb.net

 
Vista:

Pasar contactos de Outlook a tabla vb.net

Publicado por Eduardo Otiniano (13 intervenciones) el 26/09/2019 23:09:07
Hice esto:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 pasa 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 jalé 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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Pasar contactos de Outlook a tabla vb.net

Publicado por Eduardo Otiniano (13 intervenciones) el 27/09/2019 22:53:03
Para los que aún tienen el mismo problema logré solucionarlo así:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar