echohelloworld

End-To-End Check

17 posts in this topic

Hi, 

I am programming some stuff with AutoIt but i doesn't work.
I am Sending an E-Mail from 1 Account to another and i want to track that, so im logging into Profil 1 ... Sending an E-Mail with the SendMail event all fine so far.
When i log into Profil 2 the RecieveEvent does't trigger the mail is never recognized by my script.

So now im trying to log into Profil 2 and read all Mails in Inbox, the checking the Subject for my GUID which is send in Subject from Profil 1.

 

I need some help here this is for my graduation work

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the Forum!

You need to provide more information!
Which mail clients do you use to send/receive mails?
Can you post the code so have written so far?

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
#include <OutlookEX.au3>
#include <File.au3>
#include <Date.au3>
#include <_SysTray.au3>
#include <WinAPI.au3>

; Location of Logfile and outlook profile
Global Const $LogFile = @UserProfileDir & "\Desktop\End-To-End\Logs\" & @YEAR & "-" & @MON & "-" & @MDAY & ".log"
Global Const $SendProfile = "PLACEHOLDER" ;==> Profil 1
Global Const $RecieveProfile = "PLACEHOLDER" ;==> Profil 2

; Outlook Check Mail & Recepient of the testmail
Global $OutlookSendMail = False
Global $OutlookRecieveMail = False
Global $sTo = "PLACEHOLDER"
; Outlook.exe location & Timers + Retries
Local $OutlookClient = "C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE -profile "
Local $OpenTimeout = 30
Local $CloseTimeout = 30
Local $Retries = 2 ; 2 = 3 trys

; Checks if the Logfile does exists <> creates it
If Not FileExists($LogFile) Then
    _FileCreate($LogFile)
EndIf

OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries)

Func OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries)

    ; Close remaining outlook processes
    Close_Outlook()

    Local $Timer = _Date_Time_GetTickCount()

    ; Run outlook with profile parameters
    Local $Found = False
    For $i = 1 To $OpenTimeout * 4
        Status("Outlook", "Waiting " & Round($OpenTimeout - $i / 4) & " seconds for Outlook to open")
        If $i = 1 Then
            Local $runVar = $OutlookClient & $SendProfile
            Run($runVar)
            Sleep(250)
            ContinueLoop
        EndIf
        If WinExists(("[REGEXPTITLE:(Posteingang|Inbox).*Outlook]")) Then
            $Found = True
            Global $oOL = _OL_Open()
            ExitLoop
        EndIf
        Sleep(250)
    Next
    If Not $Found Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Outlook did not open within " & $OpenTimeout & " seconds")
        EndIf
        Return
    EndIf
    ;==> Outlook open with Profil 1

    If $oOL = 0 Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Unable to connect to Outlook (Error: " & @error & ")")
        EndIf
        Return
    EndIf

    ;==> generate GUID
    Local $sGUID = _WinAPI_CreateGUID()
    Local $sSubject = $sGUID
    Global $sUsedGUID = $sGUID

    ; sends an test email
    Local $oMail = _OL_Wrapper_SendMail($oOL, $sTo, "", "", $sSubject, "", "")
    If $oMail = 0 Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "_SendMail unable to send email (Error: " & @error & ")")
        EndIf
        Return
    EndIf

    ; TODO COMMENT THIS
    Local $oItems = $oOL.GetNamespace("MAPI").GetDefaultFolder($olFolderSentMail).Items
    ObjEvent($oItems, "oSend_")

    Local $Found = False
    Local $SendTimeOut = 30

    For $i = 1 To $SendTimeOut * 4
        Status("Outlook", "Waiting " & Round($SendTimeOut - $i / 4) & " seconds for Outlook to send the Email")
        If $OutlookSendMail Then
            $Found = True
            _OL_Close($oOL)
            Close_Outlook()
            Sleep(3000) ;==> Important sleep to wait until Outlook is closed, if not Profil 1 is opened again
            ExitLoop
        EndIf
        Sleep(250)
    Next
    If Not $Found Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Unable to send email within " & $SendTimeOut & " seconds")
        EndIf
        Return
    EndIf

    ;==> Start Outlook again with Profil 2
    Local $Found = False
    For $i = 1 To $OpenTimeout * 4
        Status("Outlook", "Waiting " & Round($OpenTimeout - $i / 4) & " seconds for Outlook to open")
        If $i = 1 Then
            Local $runVar = $OutlookClient & $RecieveProfile
            Run($runVar)
            Sleep(250)
            ContinueLoop
        EndIf
        If WinExists(("[REGEXPTITLE:(Posteingang|Inbox).*Outlook]")) Then
            $Found = True
            ExitLoop
        EndIf
        Sleep(250)
    Next
    If Not $Found Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Outlook did not open within " & $OpenTimeout & " seconds")
        EndIf
        Return
    EndIf
    ;==> Outlook open with Profil 2

    Local $oOL = _OL_Open()

    If $oOL = 0 Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Unable to connect to Outlook (Error: " & @error & ")")
        EndIf
        Return
    EndIf

    Local $Found = False
    Local $RecieveTimeOut = 30

    ObjEvent($oOL, "oRecieve_") ;==> RecieveEvent on Profil2 $oOL

    For $i = 1 To $RecieveTimeOut * 4
        Status("Outlook", "Waiting " & Round($RecieveTimeOut - $i / 4) & " seconds for Outlook to recieve the Email")
        If $OutlookRecieveMail Then
            $Found = True
            ExitLoop
        EndIf
        Sleep(250)
    Next
    If Not $Found Then
        If ($Retries > 0) Then
            OutlookRoutine($OutlookClient, $OpenTimeout, $CloseTimeout, $Retries - 1)
        Else
            Write_Log("Outlook", "CRITICAL", "Email was not recieved within " & $RecieveTimeOut & " seconds")
        EndIf
        Return
    EndIf

    $ElapsedTime = Round(((_Date_Time_GetTickCount() - $Timer) / 1000), 2)
    Write_Log("Outlook", "OK", "All Routines passed | time = " & $ElapsedTime)
    _OL_Close($oOL)

EndFunc   ;==>OutlookRoutine

Close_Outlook()
Exit

Func Write_Log($Key, $Status, $Message)
    Local $File = FileOpen($LogFile, $FO_APPEND)
    Local $Date = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC
    FileWrite($File, "[" & $Date & "] " & $Key & " " & $Status & " " & $Message & @CRLF)
    FileClose($File)
    If $Status = "CRITICAL" Then
        ; Screenshot
    EndIf
EndFunc   ;==>Write_Log

Func Status($OutlookClient, $Message)
    SplashTextOn($OutlookClient, $Message, -1, 150, -1, 50, 48, "")
EndFunc   ;==>Status

Func Close_Outlook()
    If ProcessExists("Outlook.exe") Then
        Local $Found = False
        For $i = 1 To 10 * 4
            Status("Outlook", "Terminating Outlook.exe")
            If $i = 1 Then
                ProcessClose("Outlook.exe")
                Sleep(250)
                ContinueLoop
            EndIf
            If Not ProcessExists("Outlook.exe") Then
                $Found = True
                ExitLoop
            EndIf
            Sleep(250)
        Next
        If Not $Found Then
            Write_Log("Outlook", "CRITICAL", "Terminating Outlook failed")
            ;Shutdown(6) ;==> Test enviroment no Shutdown
            Exit
        EndIf
    EndIf
    ClearSysTray()
EndFunc   ;==>Close_Outlook

Func ClearSysTray()
    If _FindTrayToolbarWindow(2) <> -1 Then
        $Count = _SysTrayIconCount(2)
        For $i = $Count - 1 To 0 Step -1
            $hTrayIcon = _SysTrayIconHandle($i, 2)
            $PID = WinGetProcess($hTrayIcon)
            If $PID = -1 Then
                _SysTrayIconRemove($i, 2)
            EndIf
        Next
    EndIf
EndFunc   ;==>ClearSysTray

;==> Send Event (works)
Func oSend_ItemAdd($oOL_Item)
    $OutlookSendMail = True
EndFunc   ;==>oSend_ItemAdd

;==> Recieve Event
Func oRecieve_NewMailEx($oOL_Item)
    ;==> has also to test if Subject is GUID from SendMail
    $OutlookRecieveMail = True
EndFunc

Func _WinAPI_CreateGUID()
    Local $tGUID, $aResult
    $tGUID = DllStructCreate($tagGUID)
    $aResult = DllCall("OLE32.DLL", "long", "CoCreateGuid", "ptr", DllStructGetPtr($tGUID))
    Return SetError($aResult[0] <> 0, 0, _WinAPI_StringFromGUID(DllStructGetPtr($tGUID)))
EndFunc   ;==>_WinAPI_CreateGUID

So thats what i got so far. 

Sending is no problem, but sometimes Outlook opens with Profil 1 instead of Profil 2 after SendMail was a success.

The RecieveEvent doesn't work with Profil 2, i tested all on just with Profil 1 there the RecieveEvent is working fine.

 

Thanks for your Help Water 

Share this post


Link to post
Share on other sites

Why would you need to work with two profiles in the same script?
 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

That Profil thing was my idea. I'm switching Outlook Accounts with that method. 

I just have to check if the mail i send is recieve without a problem. 
If i would check both actions sending and recieving in one account, it would not be 100% sure that there are no problems.
In a fouther step i have to log the time needed to send the mail and make notifications in our Monitoring system if the mail was 

- Not Send CRITICAL
- Not Recieved CRITICAL

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Our Exchange/Outlook system is so reliable that all mails I send get delivered. If there is anything wrong with your system then I would hunt and eliminate this problems as a first measure.

If still needed I would split the send and receive part into two scripts (like a client / server application) and run them on separate computers with the needed profiles.

Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

The Script will later be running on one Citrix Desktop and our customer has a huge Exchange Cluster with more then 5000 Inboxes.

So i can't just test in one account, and because of that i only can run one script on one machine (Citrix Desktop) i can only open one instance of Outlook at a time.

Problems over problems ... if i could run two scripts i would totaly agree with your way, but i can't.

 

One Script musst be handling Sending to Account Nr2. Open Outlook with Account Nr2. Checking if Mail is recieve. Log this to a File.
 

Share this post


Link to post
Share on other sites
2 hours ago, echohelloworld said:

The RecieveEvent doesn't work with Profil 2, i tested all on just with Profil 1 there the RecieveEvent is working fine.

This doesn't work because the mail is already in your inbox of Profil2 when you start Outlook for profil2. You would need to use _OL_ItemFind to search for the mail item with the GUID as unique key.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Another idea:

  • Add the second mailbox as a shared mailbox to your profile 1
  • Create a rule to forward test mails from the shared to your primary Inbox
  • Create a send and new mail event for your primary inbox

This way you can get rid of profile switching.

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks a lot for all of your help.
I managed to do what i want, but without using OUTLOOK UDF at all.

I'm now just looping through "sent mail" folder an looking for my GUID in Subject.
Then switching accounts a looping through inbox till the GUID is found there too.

 

Share this post


Link to post
Share on other sites

Glad you could get your task done :)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

On 10.8.2016 at 10:48 AM, water said:

Glad you could get your task done :)

Thank you ;) but it's not finished yet. 

I'm now trying to move the Outlook SysTray icon out of the "Hidden Area" so i can make a CTRL + RIGHT CLICK on it to display the RPC connection window.
I'm trying to get the informations out of the SysListView32 (SMTP-Adress, Proxyserver, Servername(Exchange), Port, and so on) to write them into a logfile.

Outlook.exe /rpcdiag don't work in this case, it doesn't shows the same data as when i CTRL + RIGHT CLICK the Tray Icon.


Do you know if it's possible to move a Tray Icon out of the "Hidden Area" so my MouseClick or ControlClick Event doesn't click into empty space?

 

#include <_SysTray.au3>
...

If Not IsDeclared("OutlookTrayIconIndex") Then
    $SearchIcon = _SysTrayIconIndex("OUTLOOK.EXE", 0, 2)
    If $SearchIcon >= 0 Then
        Local $OutlookTrayIconIndex = $SearchIcon
        Local $OutlookTrayIconPos = _SysTrayIconPos($OutlookTrayIconIndex)
        Local $hWndSysTray = _FindTrayToolbarWindow(2)
        Local $TrayText = _SysTrayIconTooltip($OutlookTrayIconIndex, 2)
;~      Exit
    EndIf
    Sleep(250)
    ContinueLoop
EndIf

...

I'm getting all needed infos about the Outlook TrayIcon from the _SysTray.au3.

Edited by echohelloworld

Share this post


Link to post
Share on other sites
_SysTrayIconHide($index, 0)

I assume this should do the trick.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

No not hide the icon, move it from the "show hidden icons" box to the system/active ones, but with AutoIt.

take a look at the attached pictures, i asume there must be a way to get the outlook icon out of the box even just for a second. 
 

 

 

2016-08-11 11_51_48-.png

2016-08-11 11_52_41-.png

Share this post


Link to post
Share on other sites

Set the flag to 0 to unhide the icon:

;===============================================================================
;
; Function Name:    _SysTrayIconHide($index, $iFlag, $iWin = 1)
; Description:      Hides / unhides any icon on systray
;
; Parameter(s):     $index      - icon index. Can be queried with _SysTrayIconIndex()
;                   $iFlag      - hide (1) or show (0) icon
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns 1 if operation was successfull or 0 if
;                   icon was already hidden/unhidden
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
1 hour ago, water said:

Set the flag to 0 to unhide the icon:

;===============================================================================
;
; Function Name:    _SysTrayIconHide($index, $iFlag, $iWin = 1)
; Description:      Hides / unhides any icon on systray
;
; Parameter(s):     $index      - icon index. Can be queried with _SysTrayIconIndex()
;                   $iFlag      - hide (1) or show (0) icon
;                   $iWin
;                   | 1         - ToolbarWindow32, Win2000+
;                   | 2         - NotifyIconOverflowWindow, Win7+
;
; Requirement(s):
; Return Value(s):  On Success - Returns 1 if operation was successfull or 0 if
;                   icon was already hidden/unhidden
;                   On Failure - Sets @error and returns -1
;                   | See _SysTrayGetButtonInfo for @error returns
;
; Author(s):        Tuape, Erik Pilsits
;
;===============================================================================

 

Still no changes, Outlook icon still remains in the Tray Icon Box

Share this post


Link to post
Share on other sites

Then I have run out of ideas :(

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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