none
per VB.NET auf Outlook lokales Postfach zugreifen RRS feed

  • Frage

  • Hallo,

    ich suche schon seit bald zwei Tagen. Ich nutze nachstehenden Code der auch soweit funktioniert.

    '// Reference to Microsoft Outlook 11.0 Object Library

     

    Imports Microsoft.Office.Interop.Outlook
    .......
    ' Create Outlook application.
    Dim oApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application
    ' Get Mapi NameSpace.
    Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace( "mapi" ) oNS.Logon( "Xyz_Configured_Outlook" , Missing.Value, False , True )
    ' Get Messages collection of Inbox.
    Dim oInbox As Microsoft.Office.Interop.Outlook.MAPIFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
    Dim oItems As Microsoft.Office.Interop.Outlook.Items = oInbox.Items
    Console.WriteLine(
    "Total : " & oItems.Count)
    ' Get unread e-mail messages.
    oItems = oItems.Restrict( "[Unread] = true" )
    Console.WriteLine(
    "Total Unread : " & oItems.Count)
    ' Loop each unread message.
    Dim oMsg As Microsoft.Office.Interop.Outlook.MailItem
    Dim i As Integer
    For i = 1 To oItems.Count
    oMsg = oItems.Item(i)
    Console.WriteLine(i)
    Console.WriteLine(oMsg.SenderName)
    Console.WriteLine(oMsg.Subject)
    Console.WriteLine(oMsg.ReceivedTime)
    Console.WriteLine(oMsg.Body)
    Console.WriteLine( "---------------------------" )
    Console.WriteLine(
    "press any key to continue" )
    Next
    ......

    Ich komme so aber nur auf mein Postfach des Outlookservers. Mit nachstendem Code kann man sich auch die Verzeichnisse herausholen. Mit Ausführung von "oFolder = oNS.PickFolder" Kommt ein Outlook-Dialog mit dem ich alle E-Mail Ordner wählen kann, nicht nur den Hauptordner sondern auch die Ordner meiner lokalen PST-Dateien.

     

    .......
    ' Create Outlook application.
    Dim oApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application
    ' Get Mapi NameSpace.
    Dim oNS As Microsoft.Office.Interop.Outlook.NameSpace = oApp.GetNamespace( "mapi" ) oNS.Logon( "Xyz_Configured_Outlook" , Missing.Value, False , True )
    Dim oFolder As Microsoft.Office.Interop.Outlook.MAPIFolder
    Dim c As String
    oFolder = oNS.PickFolder
    Dim f As Int16
    For f = 1 To oFolder.Folders.Count
    c = oFolder.Folders.Item(f).FolderPath
    Next
    ......

    Wie kann ich jetzt softwaremässig auf einen Ordner meiner lokalen PST-Dateien verweisen?

    Den Folderpath Konnte ich nicht setzen. Mit GetDefaultFolder() kommt man nur auf die systembekannten Verzeichnisse.

    Gruss Klaus

     

    Freitag, 23. April 2010 10:59

Alle Antworten

  • Es ist zwar spät für eine Antwort, aber vielleicht bringt Einen hier die Auswertung des AccountType der Accounts-Auflistung weiter:

    Imports

     

     

    System.Text

    Imports

     

     

    Outlook = Microsoft.Office.Interop.Outlook

    Public

     

     

    Class clsOutlookAccounts

     

     

    Class Sample

     

     

    Shared Sub DisplayAccountInformation(ByVal application As Outlook.Application)

     

     

    ' The Namespace Object (Session) has a collection of accounts.

     

     

    Dim accounts As Outlook.Accounts = application.Session.Accounts

     

     

    ' Concatenate a message with information about all accounts.

     

     

    Dim builder As StringBuilder = New StringBuilder()

     

     

    ' Loop over all accounts and print detail account information.

     

     

    ' All properties of the Account object are read-only.

     

     

    For Each account As Outlook.Account In accounts

     

     

    ' The DisplayName property represents the friendly name of the account.

    builder.AppendFormat(

     

    "DisplayName: {0}" & vbNewLine, account.DisplayName)

     

     

    ' The UserName property provides an account-based context to determine identity.

    builder.AppendFormat(

     

    "UserName: {0}" & vbNewLine, account.UserName)

     

     

    ' The SmtpAddress property provides the SMTP address for the account.

    builder.AppendFormat(

     

    "SmtpAddress: {0}" & vbNewLine, account.SmtpAddress)

     

     

    ' The AccountType property indicates the type of the account.

    builder.Append(

     

    "AccountType: ")

     

     

    Select Case (account.AccountType)

     

     

    Case Outlook.OlAccountType.olExchange

    builder.AppendLine(

     

    "Exchange")

     

     

    Case Outlook.OlAccountType.olHttp

    builder.AppendLine(

     

    "Http")

     

     

    Case Outlook.OlAccountType.olImap

    builder.AppendLine(

     

    "Imap")

     

     

    Case Outlook.OlAccountType.olOtherAccount

    builder.AppendLine(

     

    "Other")

     

     

    Case Outlook.OlAccountType.olPop3

    builder.AppendLine(

     

    "Pop3")

     

     

    End Select

    builder.AppendLine()

     

     

    Next

     

     

    ' Display the account information.

    Windows.Forms.

     

    MessageBox.Show(builder.ToString())

     

     

    End Sub

     

     

     

    End Class

    End

     

     

    Class

    Freitag, 31. Dezember 2010 19:39