9252Survive Posted January 23, 2016 Posted January 23, 2016 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! expandcollapse popup#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
water Posted January 23, 2016 Posted January 23, 2016 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 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
9252Survive Posted January 25, 2016 Author Posted January 25, 2016 Oh yes, that makes sense, I will put that at the end of the script and see how that goes. Thanks
9252Survive Posted January 25, 2016 Author Posted January 25, 2016 Seems like this is working! Next question, how can I use a distribution list or list of recipients here?
water Posted January 25, 2016 Posted January 25, 2016 Just enter the name of the distribution list. For a list of recipients separate them with a semicolon. 9252Survive 1 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
water Posted January 25, 2016 Posted January 25, 2016 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 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
9252Survive Posted January 25, 2016 Author Posted January 25, 2016 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)
water Posted January 25, 2016 Posted January 25, 2016 Is testmail@gmail.com correct? In your OP you use testemail@gmail.com 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
9252Survive Posted January 25, 2016 Author Posted January 25, 2016 (edited) It must be a typo while typing here ... I have checked the code its not address Its the placeholder anyways Edited January 25, 2016 by 9252Survive
water Posted January 25, 2016 Posted January 25, 2016 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 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
9252Survive Posted January 25, 2016 Author Posted January 25, 2016 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!
water Posted January 26, 2016 Posted January 26, 2016 Thanks for the feedback. Hope the INI-file approach works as well 9252Survive 1 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
9252Survive Posted February 3, 2016 Author Posted February 3, 2016 Hi, Sorry for the delay in response... The script is working fine with the INI! Thanks a lot
water Posted February 3, 2016 Posted February 3, 2016 Great 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
9252Survive Posted February 12, 2016 Author Posted February 12, 2016 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. expandcollapse popup#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)
water Posted February 12, 2016 Posted February 12, 2016 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 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
9252Survive Posted March 9, 2016 Author Posted March 9, 2016 Hello Water, Sorry, I have been tied up with some other stuff and this was side tracked I will try your suggestion and report later. Thanks again!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now