Jump to content

Help with OutlookEX - Sending Email/ Monitoring File


Recommended Posts

Hello, 

I am trying to use the latest version of OutlookEx.au3 and my script is able to send the email to the user first time but second time I am getting this error (see attached) I am trying to check a file every min and verify if the file has been modified, if the file was not modified then an email is sent. It works for the first time but fails in the second iteration. Also, attaching my code, I am very new to AutoIT, any help would be much appreciated! 

Thanks! 

 

 

#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y

#include <MsgBoxConstants.au3>
#include <Debug.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <GuiComboBox.au3>
#include <Date.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <Process.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>  ; include for file functions
#include <WinAPIFiles.au3>
#include <_SingleScript.au3>
#include <WinNet.au3>
#include <Timers.au3>
#include <INet.au3>
#include <OutlookEX.au3>
#include <DateCalc.au3>

#Region AutoIT_Options

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=No case
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
Opt("TrayAutoPause", 0) ; 0 = no pause , 1 = pause when tray icon is clicked

#EndRegion AutoIT_Options

Global $logFileName = "Test" & "-" & @YEAR &"_"&@MON& "." & "log"
Global $logfile = @ScriptDir &"\"& $logFileName
Global $LastModTime
Global $LastModTime
Global $LastModTimeStamp
Global $FiletoCheck_1
Global $FiletoCheck_2
Global $oOutlook = _OL_Open()

Func _SendAlert()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

;Global $sCurrentUser = $oOutlook.GetNameSpace("MAPI").CurrentUser.Name
;_OL_Wrapper_SendMail($oOutlook, $sCurrentUser, "", "", "Travel Time Calc Engine ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh
_OL_Wrapper_SendMail($oOutlook, "testemail@gmail.com", "", "", "ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Error sending mail. @error = " & @error & ", @extended: " & @extended)
;MsgBox(64, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Mail successfully sent to user '" & $sCurrentUser & "'!")

_OL_Close($oOutlook)

EndFunc

Func _ChecklogFile()
    $FiletoCheck_2 = FileGetTime($logfile, 0, 1)   ; Timestamp
    If $FiletoCheck_1 == $FiletoCheck_2 Then   ; if the time stamp has not changed
        Msgbox("","","File has not changed")
_SendAlert()
    Else
     Msgbox("","","File has changed")
EndIf
EndFunc

; Initial Launch, grab current GetTime
$FiletoCheck_1 = FileGetTime($logfile,0,1)
Local $YYYY = StringLeft ( $FiletoCheck_1, 4 )
Local $MM = StringMid ( $FiletoCheck_1,5,2)
Local $DD = StringMid ( $FiletoCheck_1,7,2 )
Local $HH = StringMid ( $FiletoCheck_1,9,2 )
Local $Min = StringMid ( $FiletoCheck_1,11,2 )
Local $SS = StringMid ( $FiletoCheck_1,13,2 )


$LastModTimeStamp = $YYYY&"-"&$MM&"-"&$DD&"  "&$HH&":"&$Min&":"&$SS



 While 1
 Sleep(60000)   ; check every 10 mins
    _ChecklogFile()
WEnd

 

OutlookEXError.jpg

Link to comment
Share on other sites

That's easy :)

You call _OL_Open when starting the script but immediately close Outlook after the first mail has been send in function _SendAlert.
Move _OL_Close to the main script and close Outlook before you exit the script.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Just enter the name of the distribution list. For a list of recipients separate them with a semicolon.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Just enter the name of the distribution list. For a list of recipients separate them with a semicolon.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Great thanks! I will try that

Meanwhile I am having some trouble in passing the value of the email through a variable, I keep getting the error 4400

This is what I am trying to do... 

    Global $Email = "testmail@gmail.com"

_OL_Wrapper_SendMail($oOutlook,$Email, "", "", "ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh)

 

Link to comment
Share on other sites

Is testmail@gmail.com correct? In your OP you use testemail@gmail.com

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

Can you insert

MsgBox(0, "", $email)

before _OL_Wrapper_SendMail to make sure the value hasn't been changed by the script somewhere?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

The email is correct (as declared) and the funny thing is that it's working now, not sure why it wont work earlier.  The end goal is to read this value from an INI file, I was having problems with that initially and then I tried assigning the value in the code but that didn't work either. It seems to work now, I will try to read the value from an INI and see how that goes. 

Thanks a lot for your help! 

Link to comment
Share on other sites

Thanks for the feedback. Hope the INI-file approach works as well ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 2 weeks later...

Great :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 2 weeks later...

Hi

I am again getting the same error that I posted in the beginning of this thread. The strange thing is that it works on one computer and not another. I just copied the script to another pc and it wont work and same is the case with the compiled exe. Below given is the code that uses INI file ( as I mentioned in my last post) and attached is the error. 

 

#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y

#include <MsgBoxConstants.au3>
#include <Debug.au3>
#include <File.au3>
#include <WinAPI.au3>
#include <GuiComboBox.au3>
#include <Date.au3>
#include <AutoItConstants.au3>
#include <Array.au3>
#include <Process.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>  ; include for file functions
#include <WinAPIFiles.au3>
#include <_SingleScript.au3>
#include <WinNet.au3>
#include <Timers.au3>
#include <INet.au3>
#include <OutlookEX.au3>
#include <TrayConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>


#Region AutoIT_Options

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=No case
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info
Opt("TrayAutoPause", 0) ; 0 = no pause , 1 = pause when tray icon is clicked

#EndRegion AutoIT_Options
Global $ImportFiles
Global $RootSHM
Global $Site
Global $Truck
Global $j
Global $i
Global $SiteArray
Global $MsgType
Global $TruckArray
Global $logfilepath
Global $logFileName = "Test" & "-" & @YEAR &"_"&@MON& "." & "log"

Global $LastModTime
Global $LastModTimeStamp
Global $Filecount
Global $FiletoCheck_1
Global $FiletoCheck_2
Global $oOutlook = _OL_Open()
Global $Message
Global $Email
Global $Inifile = @ScriptDir & "\FileWatcher.ini"
Global $Freq
Global $sdata
Global $Env
Global $tdata

If FileExists($Inifile) = 0 Then              ; Check if .INI file exists
_CreateIni()
EndIf

_GetValues() ; Read INI file for values

Func _CreateIni() ; IniWrite used to create the file and add section/keys.
    IniWrite($Inifile, "Project", "Root", "\\fcgwnt01\share.$\StandardHaulage\TEST\")
    IniWrite($Inifile, "Project", "Email", "TestEmail@gmail.com")
    IniWrite($Inifile, "Project", "Frequency", "60000")
    IniWrite($Inifile, "Project", "Logfile path","\\testpc\test\FileWatcher\V5")
EndFunc   ;==>_CreateIniV5


Func _GetValues() ; Read the INI File
    
    $RootSHM = IniRead($Inifile, "Project", "Root", "\\testpc\TEST\")
    $Email = IniRead($Inifile, "Project", "Email", "TestEmail@gmail.com")
    $Freq =IniRead($Inifile, "Project", "Frequency", "60000")
    $logfilepath=IniRead($Inifile, "Project", "Logfile path","\\testpc\test\FileWatcher\V5")


    If $RootSHM = "" Then
        $RootSHM = "\\testpc\TEST\"
    EndIf

    If $Email = "" Then
         $Email = "TestEmail@gmail.com"
    EndIf

    If $Freq = "" Then
        $Freq = "60000"
    EndIf

EndFunc   ;==>_GetValues

Global $logfile = $logfilepath &"\"& $logFileName



Func _SendAlert($MsgType,$Message)

If $MsgType = "0" Then
    $MsgType = "ALERT!"

Else
    If $MsgType = "1" Then
        $MsgType = "Notification-Processing Complete"

        Else
            If $MsgType = "2" Then
        $MsgType = "Notification-Processing Pending"

    EndIf


            EndIf
EndIf

If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

;Global $sCurrentUser = $oOutlook.GetNameSpace("MAPI").CurrentUser.Name
;_OL_Wrapper_SendMail($oOutlook, $sCurrentUser, "", "", " ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh
;_OL_Wrapper_SendMail($oOutlook, "TestEmail@gmail.com", "", "", " ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh)
;MsgBox("","",$Email)
_OL_Wrapper_SendMail($oOutlook,$Email, "", "", " - "& $MsgType, $Message, "", $olFormatHTML, $olImportanceHigh)
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Error sending mail. @error = " & @error & ", @extended: " & @extended)
;MsgBox(64, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Mail successfully sent to user '" & $sCurrentUser & "'!")

EndFunc

Func _ChecklogFile()
    ;$FiletoCheck_1 = FileGetTime($logfile,0,1)
    $FiletoCheck_2 = FileGetTime($logfile, 0, 1)   ; Timestamp
    If $FiletoCheck_1 == $FiletoCheck_2 Then   ; if the time stamp has not changed
        ;Msgbox("","","File has not changed")
_SendAlert(0,"An error has occurred, the log file has not changed since: " & $LastModTimeStamp)
    Else
     ;Msgbox("","","File has changed")
EndIf
EndFunc


$FiletoCheck_1 = FileGetTime($logfile,0,1)   ; Initial Launch, grab current GetTime

;MsgBox("","",$logfilepath)
;MsgBox("","",$logfile)
;MsgBox("","",$FiletoCheck_1)


Func _SplitDT($file)

Local $YYYY = StringLeft ( $file, 4 )
Local $MM = StringMid ( $file,5,2)
Local $DD = StringMid ( $file,7,2 )
Local $HH = StringMid ( $file,9,2 )
Local $Min = StringMid ( $file,11,2 )
Local $SS = StringMid ( $file,13,2 )


$LastModTimeStamp = $YYYY&"-"&$MM&"-"&$DD&"  "&$HH&":"&$Min&":"&$SS

EndFunc


 While 1
 Sleep($Freq)   ; check every 10 mins
     _SplitDT($FiletoCheck_1)
    _ChecklogFile()
    $FiletoCheck_1 = FileGetTime($logfile,0,1)  ; reset the timestamp
WEnd

_OL_Close($oOutlook)

 

2016-02-12_11-24-43.jpg

Link to comment
Share on other sites

Line

If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

should be inserted immediately after _Ol_Open because now you do not get any error information.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

  • 4 weeks later...

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

×
×
  • Create New...