Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [Vb.net] Outlook e lettura email

    Ciao a tutti, dopo ore di modifiche e studi al codice sono riuscito a gestire un po' tutto.
    Ora il mio problema principale è che non riesco a gestire il doppio archivio pst.
    Cioè per il momento cicla e mi carica tutte le e-mail presenti nel file dati predefinito (oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olF olderInbox), io vorrei se possibile leggere anche altri file dati ma non riesco a trovare una corretta soluzione.
    Ecco una parte di cordice


    codice:
      Dim objFolder As Outlook.MAPIFolder = Nothing
                Dim oApp As Outlook.Application = New Outlook.Application()
                ' Get Mapi NameSpace.
                Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
                oNS.Logon(Comboprofilo.Text, Missing.Value, False, True) ' TODO:
                Dim oInbox As Outlook.MAPIFolder
                oInbox = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    
    
                Dim oItems As Outlook.Items
    
    
                If Lista_Folders.Text = "Posta in arrivo" Then
                    oItems = oInbox.Items
                Else
                    oItems = oInbox.Folders(Lista_Folders.Text).Items
                End If
    
    
                ' Get unread e-mail messages.
                ' oItems = oItems.Restrict("[Unread] = true")
    
    
                slblMess.Text = "Totale " & oItems.Count
    
    
                ToolStripProgressBar1.Maximum = oItems.Count
    
    
                ' Loop each unread message.
                Dim oMsg As Outlook.MailItem
                Dim i As Integer
                Dim lista As ListViewItem
    
    
     .............
    .......
    ....
    qualcuno potrebbe darmi qualche dritta su come agire?!?
    Grazie anticipatamente

  2. #2
    Nessuno riesce a darmi una dritta?!?

  3. #3
    Trovata la soluzione, ecco sotto lesempio, tocca solo adattarla a piacimento, ma già funge.

    codice:
    Private Sub getOutlookEmailInfo()    Dim output As String = String.Empty
        Dim olApp As Outlook.Application = Nothing
        Dim olNameSpace As Outlook.NameSpace = Nothing
    
    
        'create new instance of Outlook.Application
        olApp = New Outlook.Application()
    
    
        'set olNameSpace to MAPI namespace
        olNameSpace = olApp.GetNamespace("MAPI")
    
    
        ' TODO: Replace the "YourValidProfile" 
        ' and "myPassword" with Missing.Value 
        ' if you want to log on with the default profile.
        ' olNameSpace.Logon("YourValidProfile", "myPassword", True, True)
        ' olNameSpace.Logon()
    
    
    
    
        'loop through stores
        For Each oStore As Outlook.Store In olNameSpace.Stores
    
    
            'root folder for store
            Dim rootFolder As Outlook.MAPIFolder = oStore.GetRootFolder()
    
    
            'folders for store
            Dim subFolders As Outlook.Folders = rootFolder.Folders
    
    
            'loop through all folders
            For Each oFolder As Outlook.Folder In subFolders
    
    
                'get folder items
                Dim oItems As Outlook.Items = oFolder.Items
    
    
                'search through each email
                For Each email As Object In oItems
    
    
                    'make sure item is a mail item,
                    'not a meeting request
                    If email.MessageClass = "IPM.Note" Then
                        If TypeOf email Is Microsoft.Office.Interop.Outlook.MailItem Then
                            output += "oStore: " + oStore.DisplayName + " oFolder: " + oFolder.Name + " " + "subject: " & email.Subject & System.Environment.NewLine
                        End If
                    End If
                Next
            Next
        Next
    
    
        'olNameSpace.Logoff()
    
    
        olNameSpace = Nothing
        olApp = Nothing
    
    
        MessageBox.Show(output)
    
    
    End Sub

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.