Neue E-Mails in öffentlichem Outlook-Ordner erkennen

  • VB.NET

    Neue E-Mails in öffentlichem Outlook-Ordner erkennen

    Hallo,

    ich würde gerne mit einem (externen EXE-)Programm, erstellt VB2010 Express, einen öffentlichen Ordner in Outlook 2010 (Exchange) "überwachen".

    Zunächst würde ich es gerne hinbekommen, dass ich
    1. überhaupt eine Rückmeldung erhalte, wenn in den öffentlichen Ordner eine Mail eingeht. Später würde ich gerne auch erkennen,
    2. ob zwischen dem letzten Programm-Ende und dem aktuellen Programm-Start neue E-Mails in den öffentlichen Ordner kamen. Ganz später will ich die
    3. dann weiter verarbeiten.

    Ich habe einen Code, mit dem dem 1. in einem normalen Postfach funktioniert (es wirkt so...):

    Quellcode

    1. Imports System
    2. Imports System.Collections.Generic
    3. Imports Microsoft.Office.Interop.Outlook
    4. Public Class Form1
    5. Private WithEvents olInboxItems As Microsoft.Office.Interop.Outlook.Items
    6. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7. Application_Startup()
    8. End Sub
    9. Private Sub Application_Startup()
    10. Dim objApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application()
    11. Dim objNS As Microsoft.Office.Interop.Outlook.NameSpace = objApp.GetNamespace("mapi")
    12. olInboxItems = objNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Items
    13. objNS = Nothing
    14. End Sub
    15. Private Sub olInboxItems_ItemAdd1(ByVal Item As Object) Handles olInboxItems.ItemAdd
    16. Panel1.BackColor = Color.Green
    17. End Sub
    18. Private Sub cmdBtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBtnReset.Click
    19. Panel1.BackColor = Color.Empty
    20. End Sub
    21. Private Sub cmdBtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBtnClose.Click
    22. Me.Close()
    23. End Sub
    24. End Class



    Bei einem öffentlichen Ordner leider nicht...:

    Quellcode

    1. Imports System
    2. Imports System.Collections.Generic
    3. Imports Microsoft.Office.Interop.Outlook
    4. Public Class Form1
    5. Private WithEvents olInboxItems As Microsoft.Office.Interop.Outlook.Items
    6. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7. Application_Startup()
    8. End Sub
    9. Private Sub Application_Startup()
    10. Dim objApp As Microsoft.Office.Interop.Outlook.Application
    11. Dim objNS As Microsoft.Office.Interop.Outlook.NameSpace
    12. Dim objPF As MAPIFolder
    13. Dim objAPF As MAPIFolder
    14. Dim objMKF As MAPIFolder
    15. objApp = New Microsoft.Office.Interop.Outlook.Application()
    16. objNS = objApp.GetNamespace("MAPI")
    17. objPF = objNS.Folders("Öffentliche Ordner - " & objNS.AddressEntry.GetExchangeUser.PrimarySmtpAddress)
    18. objAPF = objPF.Folders("Alle Öffentlichen Ordner")
    19. objMKF = objAPF.Folders("Ordner 01")
    20. olInboxItems = objNS.GetPublicFolder(objMKF).Items
    21. End Sub
    22. Private Sub olInboxItems_ItemAdd1(ByVal Item As Object) Handles olInboxItems.ItemAdd
    23. Panel1.BackColor = Color.Green
    24. End Sub
    25. Private Sub cmdBtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBtnReset.Click
    26. Panel1.BackColor = Color.Empty
    27. End Sub
    28. Private Sub cmdBtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBtnClose.Click
    29. Me.Close()
    30. End Sub
    31. End Class



    kann mir jemand einen Tipp geben?
    Ich hab auch was NewMail, NewMailEx und ItemAdd Outlook events gelesen. Wären die besser geeignet? Kann man die für eine EXE verwenden?

    Neugierige und sommerliche Grüße,
    Andreas