VB.Net – Outlook Mail löschen mit Outlook.Application

So wird es gemacht:

    '============================================
    ' VB.NET Beispiel in Visual Basic .Net
    ' © wilfried.bitz@bridgesolution.de
    '============================================
    Public Function OUTLOOK_Mail_Delete( _
        ByVal strEntryID As String) As Boolean
 
        '----------------------------------------
        Dim strProzedur As String = "Outlook_Mail_Delete"
        '----------------------------------------
 
        '----------------------------------------
        Dim oApp As Outlook.Application
        '----------------------------------------
 
        Try
 
            '------------------------------------
            'Create Outlook application. 
            oApp = New Outlook.Application()
            Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
            oNS.Logon("", Missing.Value, False, True) ' TODO: 
            Dim oProfileName As String = oNS.CurrentProfileName
            '------------------------------------
 
            '------------------------------------
            Dim oItem As Outlook.MailItem = Nothing
            If OUTLOOK_Mail_OK(oNS, oItem, strEntryID) Then
                'oItem = oNS.GetItemFromID(strEntryID)
                Debug.Print(oItem.EntryID)
                oItem.Delete()
                OUTLOOK_Mail_Delete = True
 
                If OUTLOOK_Mail_OK(oNS, oItem, strEntryID) Then
                    OUTLOOK_Mail_Delete = False
                End If
            Else
                OUTLOOK_Mail_Delete = False
            End If
            '------------------------------------
 
            '------------------------------------
            oApp = Nothing
            oNS = Nothing
            '------------------------------------
 
        Catch ex As Exception
            '------------------------------------
            'MsgBox(ex.Message)
            '------------------------------------
 
        End Try
 
    End Function
 
   Public Function OUTLOOK_Mail_OK( _
        ByRef oNS As Outlook.NameSpace, _
        ByRef oItem As Outlook.MailItem, _
        ByVal strEntryID As String) As Boolean
 
        '----------------------------------------
        Dim strProzedur As String = "Outlook_Mail_OK"
        '----------------------------------------
 
        Try
 
            '----------------------------------------
            oItem = oNS.GetItemFromID(strEntryID)
            '----------------------------------------
 
            '----------------------------------------
            OUTLOOK_Mail_OK = True
            '----------------------------------------
 
        Catch ex As Exception
 
        End Try
 
    End Function

Spendierst du mir eine Tasse Kaffee? Ich würd mich riesig freuen. DANKE !! 🙂

[wpedon id=2074]


0 Kommentare

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.