Tobit - API - Anhänge löschen

  • Ich würde gerne alle Anhänge alle Mails in einem Ordner löschen, leider gelingt mir das mit meinen AutoItscript nicht, der „Remove“ Befehl meldet einen COM-Fehler „unbekannter Name“. Hat jemand Erfahrungen, oder ein Idee?

    [autoit]


    #include <String.au3>
    #include <date.au3>
    #include <Array.au3>
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    Dim $oApp = ObjCreate("DVOBJAPILib.DvISEAPI")
    Dim $oAcc = $oApp.Logon("", "", "", "", "", "NOAUTH")
    Dim $oArchive = $oAcc.ArchiveFromID("\\dcsrv\david\archive\user\10038000\in\9")
    Dim $oEntry = $oArchive.GetArchiveEntries("default")
    Dim $oMessageItems = $oArchive.AllItems
    Dim $oMailItem

    [/autoit][autoit][/autoit][autoit]

    For $i = 0 To $oMessageItems.Count - 1
    If $oMessageItems.Item($i).Type = "2" Then
    $oMailItem = $oMessageItems.Item($i)
    If Not $oMailItem.Attachments.Count = 0 Then
    $oAttachments = $oMailItem.Attachments
    For $oAttachment In $oAttachments
    ConsoleWrite("Description: " & $oAttachment.Description & @CRLF)
    ConsoleWrite("Filename: " & $oAttachment.FileName & @CRLF)
    ConsoleWrite("Displayname: " & $oAttachment.DisplayName & @CRLF)
    ConsoleWrite("FileSize: " & $oAttachment.FileSize & @CRLF)
    ConsoleWrite("FileTime: " & $oAttachment.FileTime & @CRLF)
    ConsoleWrite("Type: " & $oAttachment.FileType & @CRLF)
    $oAttachment.Description = "Eintrag geändert: "&@HOUR&@MIN&@SEC
    $oAttachment.remove
    $oMailItem.Save
    Next
    EndIf
    EndIf
    Next

    [/autoit][autoit][/autoit][autoit]

    Func MyErrFunc()
    Local $sERR = _
    "err.description is: " & @TAB & $oMyError.description & @CRLF & _
    "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
    "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
    "err.source is: " & @TAB & $oMyError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oMyError.helpcontext
    MsgBox(0, "AutoItCOM Test", "Ein COM-Fehler ist aufgetreten !" & @CRLF & @CRLF & $sERR)
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    Local $g_eventerror = $err
    EndFunc ;==>MyErrFunc

    [/autoit]

    2 Mal editiert, zuletzt von kunstlust (5. Dezember 2011 um 09:27)

  • Nun gibt es doch noch einen Fehler, sowie es mehr als ein Anahng ist, stürtzt das Script ab, aber es werden alle Anhänge bis auf den letzten gelöscht, hat jemand eine Idee?

  • Das Problem habe ich nun so gelöst: :D

    [autoit]


    #include <String.au3>
    #include <date.au3>
    #include <Array.au3>
    Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
    Dim $oApp = ObjCreate("DVOBJAPILib.DvISEAPI")
    Dim $oAcc = $oApp.Logon("", "", "", "", "", "NOAUTH")
    Dim $oArchive = $oAcc.ArchiveFromID("\\dcsrv\david\archive\user\10038000\in\9")
    Dim $oEntry = $oArchive.GetArchiveEntries("default")
    Dim $oMessageItems = $oArchive.AllItems
    Dim $oMailItem

    [/autoit][autoit][/autoit][autoit]

    For $i = 0 To $oMessageItems.Count - 1
    If $oMessageItems.Item($i).Type = "2" Then
    $oMailItem = $oMessageItems.Item($i)
    If $oMailItem.Attachments.Count > 0 Then
    $oAttachments = $oMailItem.Attachments

    [/autoit][autoit][/autoit][autoit]

    For $t = 1 To $oMailItem.Attachments.Count
    $oAttachment = $oAttachments.Item(0)
    ConsoleWrite("Description: " & $oAttachment.Description & @CRLF)
    ConsoleWrite("Filename: " & $oAttachment.FileName & @CRLF)
    ConsoleWrite("Displayname: " & $oAttachment.DisplayName & @CRLF)
    ConsoleWrite("FileSize: " & $oAttachment.FileSize & @CRLF)
    ConsoleWrite("FileTime: " & $oAttachment.FileTime & @CRLF)
    ConsoleWrite("Type: " & $oAttachment.FileType & @CRLF)
    $oAttachment.Description = "Eintrag geändert: "&@HOUR&@MIN&@SEC

    [/autoit][autoit][/autoit][autoit]

    $oAttachments.Remove($oAttachment)

    [/autoit][autoit][/autoit][autoit]

    Next
    $oMailItem.Save
    EndIf
    EndIf
    Next

    [/autoit][autoit][/autoit][autoit]

    Func MyErrFunc()
    Local $sERR = _
    "err.description is: " & @TAB & $oMyError.description & @CRLF & _
    "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
    "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
    "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
    "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
    "err.source is: " & @TAB & $oMyError.source & @CRLF & _
    "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
    "err.helpcontext is: " & @TAB & $oMyError.helpcontext
    MsgBox(0, "AutoItCOM Test", "Ein COM-Fehler ist aufgetreten !" & @CRLF & @CRLF & $sERR)
    Local $err = $oMyError.number
    If $err = 0 Then $err = -1
    Local $g_eventerror = $err
    EndFunc ;==>MyErrFunc

    [/autoit]