Jump to content

OutlookEX UDF


water
 Share

Recommended Posts

Posted (edited)

Hello water,

Thank you for answering.

I know that $olMSGUnicode is a constant. But in _OL_ItemSave, I have to set $itype ? It is not optional, or is it?

Quote

_OL_ItemSave($oOL, $vItem, $sStoreID, $sPath, $iType[, $iFlags = 1])

$iType    - The file type to save. Is defined by the Outlook OlSaveAsType enumeration

When I save the mail, I always get msg files. When I save it twice, I get two msg files with different sizes (i.e. 198 kb and 199 kb). When I open the first msg file, it is displayed as plain text (no formatted text, no logos, etc.). The second (and all further msg-files of this mail) is displayed normally as HTML.

Really strange in my opinion. I'm not sure this is an AutoIt or OutlookEX problem, but I need a workaround.

Greetings

Matthias

Edited by corbeau56
Link to comment
Share on other sites

Posted (edited)

Could you please create a stripped down reproducer script?
If this works we can sort out AutoIt and the OutlooKEX UDF.

; Manually select a mail item to save
_OL_FolderSelectionGet
_OL_ItemSave
MsgBox ; So you can check the result of ItemSave
_OL_ItemSave

BTW:
Which version of Outlook and OutlookEX (please see variable $__g_sVersionOutlookEX in the UDF) do you run?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Posted (edited)
5 hours ago, water said:

Could you please create a stripped down reproducer script?
If this works we can sort out AutoIt and the OutlooKEX UDF.

; Manually select a mail item to save
_OL_FolderSelectionGet
_OL_ItemSave
MsgBox ; So you can check the result of ItemSave
_OL_ItemSave

BTW:
Which version of Outlook and OutlookEX (please see variable $__g_sVersionOutlookEX in the UDF) do you run?

I am using 

Quote

Global $__g_sVersionOutlookEX = "OutlookEX: 1.7.0.1 2022-08-21"

A stripped down script might be:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=Projektwahl.exe
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 AutoIt Version:             3.3.14.5
 Autor:                      Matthias Weber
 Version:                    1.2
#ce ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include <WinAPI.au3>
#include <OutlookEX.au3>
#include <File.au3>
#include <Array.au3>
#include <WinAPIFiles.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Const $win_Outlook = "rctrl_renwnd32" ;     Fensterklasse Outlook Anwendung
Global $fclass, $fhandle
HotKeySet("^{NUMPADDOT}", "Mailablage")
;Endlosschleife hält Skript im Hintergrund am Leben
While 1
    Sleep(5)
WEnd
; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
; Funktion Mailablage, ausgelöst durch STRG-Komma (Zehnerblock) oder STRG-ä
Func Mailablage()
    Local $pfad, $i_abs
    ; frage Handle und Class des aktuellen Fensters ab
    $fhandle = WinGetHandle("[ACTIVE]")
    $fclass = _WinAPI_GetClassName($fhandle)
    ; falls Outlook-Fenster
    If $fclass = $win_Outlook Then
        ; Verbindung zu Outlook öffnen
        Local $oOutlook = ObjGet("", "Outlook.Application")
        ; nur wenn Verbindung zu Outlook gelingt
        If IsObj($oOutlook) Then
            ; Verbindung zum ausgewählten Objekt öffnen (das, welches gerade in Outlook markiert ist)
            Local $aReturn = _OL_FolderSelectionGet($oOutlook)
            ; abfragen, von welchem Typ es ist (Mail, Kontakt, Termin...)
            Local $olClass = _OL_ItemGet($oOutlook, $aReturn[1][1], Default, "MessageClass")[1][1]
            ; nur wenn das Item eine Mail ist
            If $olClass = "IPM.Note" Then
                Local $dateiname= "C:\Temp\Test.msg"
                ; dann Mail speichern
                Local $olEntryID = _OL_ItemGet($oOutlook, $aReturn[1][1], Default, "EntryID")[1][1]
                _OL_ItemSave($oOutlook, $olEntryID, Default, $dateiname, $olMsg, 1)
                ;  falls Fehler beim Speichern: Fehlercode anzeigen
                If @error <> 0 Then MsgBox(0, "Error while saving. Code: ", @error)
            EndIf
        Else
            ; Verbindung zu Outlook fehlgeschlagen
            MsgBox(0, "!!!", "No connection to Outlook!")
        EndIf
        ; If (aktuelles Fenster ist Outlook)
    EndIf
EndFunc   ;==>Mailablage

This minimal script shows the same behaviour. _OL_ItemSave does not report any error, but the first saved msg file is still "corrupt", all other saves msg files are ok. By the way: when I select a "corrupt" msg-file in Windows Explorer and activate the preview window then the mail is shown correctly as formatted text. When I doubleclick it to open it, it shows plain text. Really confusing.

By the time, I replaced all OutlookEX functions by raw functions or properties, and now it seems to work (all saved msg files are displayed as HTML when opened again). Here is my modified script, which works without #include <OutlookEX.au3>. 

; Funktion Mailablage, ausgelöst durch STRG-Komma (Zehnerblock) oder STRG-ä
Func Mailablage()
    Local $pfad, $i_abs
    ; frage Handle und Class des aktuellen Fensters ab
    $fhandle = WinGetHandle("[ACTIVE]")
    $fclass = _WinAPI_GetClassName($fhandle)
    ; falls Outlook-Fenster
    If $fclass = $win_Outlook Then
        ; Verbindung zu Outlook öffnen
        Local $oOutlook = ObjGet("", "Outlook.Application")
        ; nur wenn Verbindung zu Outlook gelingt
        If IsObj($oOutlook) Then
            ; Objekt des ausgewählten Items holen (das, welches gerade in Outlook markiert ist)
            Local $oItem = $oOutlook.ActiveExplorer.Selection.Item(1)
            ; abfragen, von welchem Typ es ist (Mail, Kontakt, Termin...)
            ; nur wenn das Item eine Mail ist (Objekttyp 43)
            If $oItem.Class = 43 Then
                ; ermittele wichtige Eigenschaften der Mail
                Local $olSender = $oItem.ItemProperties.Item("SenderEmailAddress").Value
                Local $olDate = $oItem.ItemProperties.Item("CreationTime").Value
                Local $olSubject= $oItem.ItemProperties.Item("Subject").Value
                ; prüfen, ob schon gespeichert
                $i_abs = _ArraySearch($projekterkennung, $olSender, 0, 0, 0, 0, 1)
                If $i_abs > 0 Then
                    ; wenn gefunden, dann PN im Combo speichern und als Default setzen
                    GUICtrlSetData($Combo_PN, $projekterkennung[$i_abs][1], $projekterkennung[$i_abs][1])
                    ; Labeltext anpassen und auf grün umstellen
                    GUICtrlSetData($Label_PN, "Projektnummer aus Absender erkannt:")
                    GUICtrlSetColor($Label_PN, 0x107C10)
                Else
                    ; Labeltext anpassen und auf schwarz umstellen
                    GUICtrlSetData($Label_PN, "Bitte Projektnummer eingeben oder auswählen:")
                    GUICtrlSetColor($Label_PN, 0x000000)
                EndIf
                ; Hole Projektnummer
                $pfad = GetProj()
                ; nur wenn Eingabe erfolgt
                If $pfad <> "" Then
                    ; wenn Absender "@xxx.de" enthält, dann ersetze Absender durch "xxx"
                    If (StringInStr($olSender, "@xxx.de") > 0 Or StringInStr($olSender, "/o=XXX/") > 0) Then
                        Local $absender = "xxx"
                    Else
                        Local $absender = $olSender
                    EndIf
                    ; ermittele Sendedatum der Mail und formatiere es richtig
                    Local $datum = StringLeft($olDate, 4) & "-" & StringMid($olDate, 5, 2) & "-" & StringMid($olDate, 7, 2)
                    ; ermittele Betreff der Mail und lösche unzulässige Zeichen
                    ; zum Entfernen von Backslash und Anführungszeichen müssen diese innerhalb der eckigen Klammern doppelt stehen!
                    Local $betreff = StringRegExpReplace($olSubject, "[<>/\\|?*:,;""]", "")
                    ; Mehrfachleerzeichen durch Einfachleerzeichen ersetzen, ggf. mehrfach
                    While StringInStr($betreff, "  ") > 0; solange ein doppeltes Leerzeichen gefunden wird
                        $betreff = StringRegExpReplace($betreff, "  ", " "); ersetze doppeltes Leerzeichen durch einfaches Leerzeichen
                    WEnd
                    ; alle Leerzeichen durch Unterstriche ersetzen
                    $betreff = StringRegExpReplace($betreff, " ", "_")
                    ; überlange Betreffzeilen kürzen
                    If StringLen($betreff) > 50 Then $betreff = StringLeft($betreff, 30) & "..." & StringRight($betreff, 17)
                    Local $nproj = StringRight($pfad, 5)
                    ; Variable pfad erweitern, neue Ordnerstruktur ab 16300 berücksichtigen
                    If Number($nproj) >= 16300 Then
                        $pfad = $pfad & "\Kommunikation\"
                    Else
                        $pfad = $pfad & "\Faxe_E-Mails\"
                    EndIf
                    ; Prompt für Dateinamen (Vorschlag) erzeugen
                    Local $prompt = $nproj & "_" & $datum & "_" & $absender & "_" & $betreff & ".msg"
                    ; endgültigen Dateinamen über Standarddialog holen, dabei $prompt als Vorschlag anbieten
                    Local $dateiname = FileSaveDialog("ifb-Mail speichern (c)ifb(Wb) 2020-2023", $pfad, "Outlook-Nachrichtenformat - Unicode (*.msg)", 0, $prompt)
                    ; falls nicht Escape gewählt
                    If $dateiname <> "" Then
                        ; Dateinamen auf schon vorhanden prüfen und ggf. anpassen (externe Funktion)
                        $dateiname = NextMsgFilename($dateiname)
                        ; dann Mail speichern (9 = Dateityp msg UniCode)
                        $oItem.SaveAs($dateiname, 9)
                        ;  falls Fehler beim Speichern: Fehlercode anzeigen
                        If @error <> 0 Then MsgBox(0, "Fehler beim Speichern! Fehlercode: ", @error)
                        ; Absender, zugehörige PN und Datum in SQL-Datenbank speichern, aber nur, wenn es nicht "ifb" ist
                        If $absender <> "ifb" Then SQL_AddItem($absender, $nproj, $datum)
                        ; setze Kategorie der Mail in Outlook auf "gespeichert"
                        $oItem.ItemProperties.Item("Categories").Value = "gespeichert"
                        ;  falls Fehler beim Ändern der Kategorie: Fehlercode anzeigen
                        If @error <> 0 Then MsgBox(0, "Fehler beim Ändern der Kategorie! Fehlercode: ", @error)
                    Else
                        ; in der Dateiauswahl Esc bzw. Abbrechen gewählt --> Warnhinweis anzeigen
                        MsgBox(0, "Wb informiert:", "E-Mail wurde nicht gespeichert!")
                    EndIf
                    ; If (Projektnummer eingegeben)
                EndIf
                ; If (Mail-Item ausgewählt)
            EndIf
        Else
            ; Verbindung zu Outlook fehlgeschlagen
            MsgBox(0, "Wb informiert:", "Verbindung zu Outlook nicht möglich!" & Chr(10) & "Passiert i.A. kurz nach dem Starten von Outlook." & Chr(10) & "Bitte kurz warten und nochmal versuchen.")
        EndIf
        ; If (aktuelles Fenster ist Outlook)
    EndIf
EndFunc   ;==>Mailablage

Greetings

Matthias

Edited by corbeau56
Link to comment
Share on other sites

Werde ich prüfen, sobald ich etwas Zeit finde und Outlook unter Windows 11 🥵 korrekt funktioniert!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • 1 month later...

I checked the code high and low but could not find an error nor could I reproduce your problem. As you have a working script right now I suggest to stay with your version of _OL_ItemSave.
If another problem with this function arises we can give it another go.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...