Outlook-Regel als Parameter übergeben?

  • Hallo Leute,

    ich habe eine Outlook-Regel eingerichtet. Wenn im Betreff "Lade Programm vom FTP" steht, dann wird eine EXE-Datei ausgeführt.
    In der erste Zeile der Nachricht steht z.B. "10.2". Wie kann ich die Inhalt der erste Zeile der Nachricht an AutoIT übergeben?

    Besten Dank vorab!

    Viele Grüße,
    Dino

    Einmal editiert, zuletzt von Dino (19. März 2012 um 11:14)

  • Welche Nachricht? Du meinst die Email oder wie?

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Ich denke, dass zumindest die EntryID der Mail an das Skript übergeben wird. Mit meiner OutlookEX UDF kannst Du damit auf die Mail zugreifen und die gewünschten Daten auslesen.

  • chip: ja, die E-Mail

    water: Wie ist das Kommando, wenn ich ein oder mehrere Wörter suchen möchte?

    [autoit]

    $aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "[Subject] = 'test'", "", "", "", "", 1)

    [/autoit]
  • An das Skript das von der Rule aufgerufen wird, wird die EntryID der Mail übergeben.
    Greif mit

    [autoit]

    $vOL_Item = $CmdLine[1]
    $oOL = _OL_Open()
    $aResult = _OL_ItemGet($oOL, $vOL_Item, Default, "body,subject")
    _OL_Close($oOL)

    [/autoit]

    darauf zu. Wobei $vOL_Item die EntryID ist. Du erhältst eine zwei dimensionale Tabelle mit den angeforderten properties.

  • Was kriegst Du, wenn Du Dir $CmdLine[0] (Anzahl der Parameter) ausgeben lässt?

  • Sieht aus, als ob das Skript in Outlook VBA geschrieben werden muss.
    Gute Beispiele gibt es hier. Zur Not könnte das VBA Skript dann das AutoIt Skript aufrufen - habe ich aber noch nie gemacht.

  • Hallo water,

    $cmdline[0] ergibt 0 wie auch bei $cmdlineraw schon zu sehen war.
    Wir haben uns überlegt das die Regel ein Autoitscript anstösst und dann wird jede neu erhaltene Mail mit deiner OutlookEx ausgelesen.
    Bitte gib uns ein Beispiel wie man ein Wort innerhalb des Betreff sucht.
    Wir haben schon mit den like SQL Anweisungen fast alles probiert, aber die schreibweisen wie sie bei Microsoft beschrieben werden funktionieren nicht.
    [Subject] = "test" funktioniert ja aber es werden nur alle Mails mit genau diesem Betreff rausgefiltert. Wir suchen *test*

    Gruß und Danke

  • Wenn Du im Feld "Subject" nach eine SubString suchen möchtest, dann geht das so:

    [autoit]

    $aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "", "Subject", "test", "", "", 1)

    [/autoit]


    Die Parameter $sOL_SearchName und $sOL_SearchValue definieren, nach welchem Wert in welchem Feld gesucht werden soll (Funktion StringInStr).
    Nur ein Vergleich mit einem Feld ist möglich.

    Die Suchmöglichkeiten von Outlook sind leider ziemlich eingeschränkt bzw. sehr komplex. Guckst Du hier .

  • Hallo water,

    wir haben es jetzt wie folgt gelöst:

    [autoit]

    $filter = '[LastModificationTime] > "' & @MON & "/" & @MDAY & "/" & @YEAR & '"' ;03/15/2012"'
    $aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, $filter, "Subject", "lade", "", "", 1)
    If @error = 0 Then
    Else
    MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", "Error finding a contact. @error = " & @error & ", @extended: " & @extended)
    EndIf
    $version = Stringsplit($aItems[1][0], " ")
    MsgBox(1,"","Ich lade " & $version[3])

    [/autoit]

    Besten Dank für die Unterstützung!

    Viele Grüße,
    Dino

  • Hallo Dino,

    sollte mir mal fad sein, dann versuche ich mich mal an einer erweiterten Suchfunktion (Strg+Shift+F).
    Mal sehen.

    Schöne Grüße
    water

  • Hallo Dino,

    hier ein erster Versuch. Doku etc. noch unvollständig aber die Beispiele funktionieren.
    Die Beispiele durchsuchen die Inbox nach den in den Variablen $sStringx angegebenen Inhalten. Bitte einfach diese Variablen für Deine Umgebung anpassen.

    Spoiler anzeigen
    [autoit]

    #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
    #include <OutlookEX.au3>
    $iOL_Debug = 2

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

    ; *****************************************************************************
    ; Create test environment
    ; *****************************************************************************
    Global $oOutlook = _OL_Open()
    If @error Then Exit MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_Open. @error = " & @error & ", @extended = " & @extended)
    ;Global $iResult = _OL_TestEnvironmentCreate($oOutlook)
    ;If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF - Manage Test Environment", "Error creating the test environment. @error = " & @error)
    Global $aFolder = _OL_FolderAccess($oOutlook, "", $olFolderInbox)
    If @error Then Exit MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_Open. @error = " & @error & ", @extended = " & @extended)

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

    ; *****************************************************************************
    ; Example 1
    ; Search the subject of mail items containing $sString1 or
    ; starting with $sString2
    ; Returns: Subject, CreationTime, Sendername
    ; *****************************************************************************
    Global $sString1 = "nicht", $sString2 = "DEMI"
    Global $aSearchArray[3][4] = [[2, 4],[0x0037001E, 3, $sString1, "or"],["subject", 2, $sString2, ""]]
    Global $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $olMail, $aSearchArray, "subject,CreationTime,Sendername")
    If @error Then
    MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_ItemSearch. @error = " & @error & ", @extended = " & @extended)
    Else
    _Arraydisplay($aResult, "Example 1")
    EndIf

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

    ; *****************************************************************************
    ; Example 2
    ; Same as example 1 but filter specified in DASL format
    ; Returns: EntryID, Subject, CreationTime, Sendername
    ; *****************************************************************************
    Global $sFilter = "@SQL=""http://schemas.microsoft.com/mapi/proptag/0x0037001E"" ci_phrasematch '" & $sString1 & "' or ""http://schemas.microsoft.com/mapi/proptag/0x0037001E"" ci_startswith '" & $sString2 & "'"
    $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $olMail, $sFilter, "EntryID,Subject,CreationTime,Sendername")
    If @error Then
    MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_ItemSearch. @error = " & @error & ", @extended = " & @extended)
    Else
    _Arraydisplay($aresult, "Example 2")
    EndIf

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

    ; *****************************************************************************
    ; Example 3
    ; Search the subject of mail items with exact matching $sString3
    ; Returns: EntryID, Subject
    ; *****************************************************************************
    Global $sString3 = "cert"
    Global $aSearchArray[2][4] = [[1, 4],[0x0037001E, 1, $sString3]]
    $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $olMail, $aSearchArray, "EntryID,Subject")
    If @error Then
    MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_ItemSearch. @error = " & @error & ", @extended = " & @extended)
    Else
    _Arraydisplay($aresult, "Example 3")
    EndIf

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

    ; *****************************************************************************
    ; Example 4
    ; Search the body of mail items for phrase $sString4
    ; Returns: EntryID, Subject, max 255 characters of the body
    ; *****************************************************************************
    Global $sString4 = "Kamera"
    $sFilter = "@SQL=""urn:schemas:httpmail:textdescription"" ci_phrasematch '" & $sString4 & "'"
    $aResult = _OL_ItemSearch($oOutlook, $aFolder[1], $olMail, $sFilter, "EntryID,Subject,urn:schemas:httpmail:textdescription")
    If @error Then
    MsgBox(16, "OutlookEX UDF - _OL_ItemSearch Example Script", "Error running _OL_ItemSearch. @error = " & @error & ", @extended = " & @extended)
    Else
    _Arraydisplay($aresult, "Example 4")
    EndIf

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

    _OL_Close($oOutlook)
    Exit

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _OL_ItemSearch
    ; Description ...: Find items (extended search) using a DASL query returning an array of all specified properties.
    ; Syntax.........: _OL_ItemSearch($oOL, $vOL_Folder, $iOL_ObjectClass, $avOL_Search, $sOL_ReturnProperties[, $sOL_Sort = ""[, $iOL_Flags = 0]])
    ; Parameters ....: $oOL - Outlook object returned by a preceding call to _OL_Open()
    ; $vOL_Folder - Folder object as returned by _OL_FolderAccess or full name of folder where the search will be started.
    ; +If you want to search a default folder you have to specify the folder object.
    ; $iOL_ObjectClass - Class of items to search for. Defined by the Outlook OlObjectClass enumeration (default = Default = $olContact)
    ; $avOL_Search - Can bei either a string containing the full DASL query or a one based two-dimensional array with unlimited number of rows containing the elements to build the DASL query:
    ; |0: Property to query. This can be either the hex value or the name of the property. The function transaltes the name to the hex value. Unknown names set @error
    ; |1: Type of comparison operator: 1 = "=", 2 = "ci_startswith", 3 = "ci_phrasematch", 3 = "like"
    ; |2: Value to search for
    ; |3: Operator to concatenate the next comparison. Has to be "and", "or", "or not" or "and not"
    ; For details please see Remarks
    ; $sOL_ReturnProperties - Comma separated list of properties to return. Can be the property name (e.g. "subject") or the MAPI proptag (e.g. "http://schemas.microsoft.com/mapi/proptag/0x10F4000B")
    ; $sOL_Sort - Optional: Property to sort the result on plus optional flag to sort descending (default = None). E.g. "[Subject], True" sorts the result descending on the subject
    ; $iOL_Flags - Optional: Flags to set different processing options. Can be a combination of the following:
    ; |1: Subfolders will be included
    ; |2: Row 1 contains column headings. Therefore the number of rows/columns in the table has to be calculated using UBound
    ; |4: Just return the number of records. You don't get an array, just a single integer denoting the total number of records found
    ; Return values .: Success - One based two-dimensional array with the properties specified by $sOL_ReturnProperties
    ; Failure - Returns "" and sets @error:
    ; |1 - $oOL is not an object
    ; |2 - Error accessing the specified folder. See @extended for errorcode returned by _OL_FolderAccess
    ; |3 - $iOL_ObjectClass is not an integer
    ; |4 - $avOL_Search is an array but not a two dimensional array or the first row doesn't contain the numbers of rows and columns
    ; |5 - $sOL_ReturnProperties is empty
    ; |6 - Specified search property could not be translated to a hex code. @extended is set to the row in $avOL_Search
    ; |7 - Specified search operator is not an integer or < 1 or > 3. @extended is set to the row in $avOL_Search
    ; |8 - Specified search value is empty. @extended is set to the row in $avOL_Search
    ; |9 - Error splitting $sOL_ReturnProperties
    ; |10 - Error adding $sOL_ReturnProperties to the result set. @extended is the number of the property in error
    ; |11 - Invalid search operator. Must be "and" or "or". @extended is set to the row in $avOL_Search
    ; |12 - The last entry in the search array has a search operator
    ; |13 - The entry in the search array has no operator but more search arguments follow
    ; |14 - Error executing the search operation. @extended is set to the error returned by method GetTable
    ; |15 - No records returned by the search operation
    ; Author ........: water
    ; Modified ......:
    ; Remarks .......: DASL syntax: "Searching Outlook Data" - http://msdn.microsoft.com/en-us/library/cc513841.aspx"
    ; List of MAPI proptags: - http://www.dimastr.com/redemption/enum_MAPITags.htm
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; ===============================================================================================================================
    Func _OL_ItemSearch($oOL, $vOL_Folder, $iOL_ObjectClass, $avOL_Search, $sOL_ReturnProperties);, $sOL_Sort = "", $iOL_Flags = 0)

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

    Local $asOL_Operator[5] = [4, "=", "ci_startswith", "ci_phrasematch", "like"]
    Local $sOL_Filter = '@SQL=', $aOL_Temp, $sOL_Property, $iOL_Rows, $iOL_Cols, $oOL_Row
    If Not IsObj($oOL) Then Return SetError(1, 0, "")
    If Not IsObj($vOL_Folder) Then
    $aOL_Temp = _OL_FolderAccess($oOL, $vOL_Folder)
    If @error Then Return SetError(2, @error, "")
    $vOL_Folder = $aOL_Temp[1]
    EndIf
    If Not IsInt($iOL_ObjectClass) Then Return SetError(3, 0, "")
    If StringStripWs($sOL_ReturnProperties, 7) = "" Then Return SetError(5, 0, "")
    Local $aOL_ReturnProperties = StringSplit(StringStripWS($sOL_ReturnProperties, 8), ",")
    If @error Then Return SetError(9, 0, "")
    ; Build search string
    If IsArray($avOL_Search) Then
    If UBound($avOL_Search, 0) <> 2 Or Not IsInt($avOL_Search[0][0]) Or Not IsInt($avOL_Search[0][1]) Then Return SetError(4, 0, "")
    Local Const $sPropTag = "http://schemas.microsoft.com/mapi/proptag/"
    For $iOL_Index = 1 To $avOL_Search[0][0]
    If IsInt($avOL_Search[$iOL_Index][0]) Then
    $sOL_Property = "0x" & Hex(Int($avOL_Search[$iOL_Index][0]))
    Else
    $sOL_Property = __OL_Property2Hex($avOL_Search[$iOL_Index][0])
    If @error Then Return SetError(6, $iOL_Index, "")
    Endif
    If Not IsInt($avOL_Search[$iOL_Index][1]) Or $avOL_Search[$iOL_Index][1] < 1 Or $avOL_Search[$iOL_Index][1] > 3 Then Return SetError(7, $iOL_Index, "")
    $avOL_Search[$iOL_Index][2] = StringStripWS($avOL_Search[$iOL_Index][2], 7)
    If $avOL_Search[$iOL_Index][2] = "" Then Return SetError(8, $iOL_Index, "")
    $avOL_Search[$iOL_Index][3] = StringStripWS($avOL_Search[$iOL_Index][3], 7)
    If $avOL_Search[$iOL_Index][3] <> "" Then
    If $avOL_Search[$iOL_Index][3] <> "and" And $avOL_Search[$iOL_Index][3] <> "or" And _
    $avOL_Search[$iOL_Index][3] <> "and not" And $avOL_Search[$iOL_Index][3] <> "or not" _
    Then Return SetError(11, $iOL_Index, "")
    If $iOL_Index = $avOL_Search[0][0] Then Return SetError(12, $iOL_Index, "")
    Else
    If $iOL_Index < $avOL_Search[0][0] Then Return SetError(13, $iOL_Index, "")
    EndIf
    $sOL_Filter = $sOL_Filter & '"' & $sPropTag & $sOL_Property & '" ' & $asOL_Operator[$avOL_Search[$iOL_Index][1]] & " '" & $avOL_Search[$iOL_Index][2] & "'"
    If $avOL_Search[$iOL_Index][3] <> "" Then $sOL_Filter = $sOL_Filter & " " & $avOL_Search[$iOL_Index][3] & " "
    Next
    Else
    $sOL_Filter = $avOL_Search
    EndIf
    ; execute the search
    Local $oOL_Table = $vOL_Folder.GetTable($sOL_Filter)
    If @error Or Not IsObj($oOL_Table) Then Return SetError(14, @error, "")
    If $oOL_Table.GetRowCount = 0 Then Return SetError(15, 0, "")
    ; http://msdn.microsoft.com/en-us/library/…fice.12%29.aspx
    ; Remove all columns in the default column set
    $oOL_Table.Columns.RemoveAll
    ; Specify desired properties
    For $iOL_Index = 1 To $aOL_ReturnProperties[0]
    $oOL_Table.Columns.Add($aOL_ReturnProperties[$iOL_Index])
    If @error Then Return SetError(10, $iOL_Index, "")
    Next
    ; Create and fill the result table
    $iOL_Rows = $oOL_Table.GetRowCount + 1
    If @error Then Return SetError(14, @error, "")
    $iOL_Cols = $aOL_ReturnProperties[0]
    Local $avOL_Result[$iOL_Rows][$iOL_Cols] = [[$iOL_Rows - 1, $iOL_Cols]]
    Local $iOL_Index2 = 1
    While Not $oOL_Table.EndOfTable
    $oOL_Row = $oOL_Table.GetNextRow
    For $iOL_Index = 1 To $aOL_ReturnProperties[0]
    $avOL_Result[$iOL_Index2][$iOL_Index-1] = $oOL_Row($aOL_ReturnProperties[$iOL_Index])
    Next
    $iOL_Index2 = $iOL_Index2 + 1
    WEnd
    Return $avOL_Result

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

    EndFunc ;==>_OL_ItemSearch

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

    Func __OL_Property2Hex($sOL_Property)

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

    Local $aProperties[100][2] = [[2, 2],["subject", "0x0037001E"],["SenderName","0x0C1A001F"]]
    For $i = 1 To $aProperties[0][0]
    If $aProperties[$i][0] = $sOL_Property Then Return $aProperties[$i][1]
    Next
    Return SetError(1, 0, "")

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

    EndFunc ;==>__OL_Property2Hex

    [/autoit]