9252Survive

Help with OutlookEX - Sending Email/ Monitoring File

18 posts in this topic

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

Share this post


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

Oh yes, that makes sense, I will put that at the end of the script and see how that goes. 

Thanks

Share this post


Link to post
Share on other sites

Seems like this is working!  :)

Next question, how can I use a distribution list or list of recipients here?  

Share this post


Link to post
Share on other sites

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

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

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 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

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)

 

Share this post


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

#9 ·  Posted (edited)

It must be a typo while typing here ... I have checked the code its not address

Its the placeholder anyways 

Edited by 9252Survive

Share this post


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

Sure, let me check that... 

Share this post


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

Share this post


Link to post
Share on other sites

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

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

Hi, 

Sorry for the delay in response...

The script is working fine with the INI!

 

Thanks a lot

Share this post


Link to post
Share on other sites

Great :)


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

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

Share this post


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

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! 

 

 

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

  • Similar Content

    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )

       
    • nassausky
      By nassausky
      Hey all,
      Has anyone created any queries for youtube? I was thinking it might be something like this but can't quite figure it out:
      $oIE = _IECreateEmbedded() _IENavigate($oIE,"https://www.youtube.com") Local $oForms = _IETagNameGetCollection($oIE, "form") Local $sTxt = "" For $oForm In $oForms If $oForm.id = "masthead-search" Then $oInputs = _IETagNameGetCollection($oIE, "input") For $oInput In $oInputs If $oInput.id = "masthead-search-term" Then _IEFormElementSetValue($oInput, "cards") _IEFormSubmit($oForm) EndIf Next EndIf Next  
    • Skysnake
      By Skysnake
      Scite comes up occasional, almost incidentally, in some support topics.  I have not found a "Scite" topic in the forums, so this is where I will start.  I have recently been using Scite intensively, specifically with a large project and I have certain issues.  I know that Scite is not an AutoIt product, but it is so closely integrated to the core release that it makes sense to raise issues and request support here.  If this is not the right please refer me to the right forum.
      Thx
       
      Skysnake