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

    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
    • sree161
      By sree161
      Hi,
      i have a code which generates two numeric outputs.i have to save them in excel.
      Is there any way to export them to specific cells in excel???
    • TotalAuto
      By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
    • hugomito
      By hugomito
      Hi all,
      I built an AutoIt application that interacts with several other applications/software. Now, it's turn to interfact with Visual Studio Team Services (VSTS).
      Does anyone has a blog, demo, script to share?
      Thanks!
    • Viki
      By Viki
      This is my first time here so please dont bombard me that what a silly question I am asking!!
      I have 500 rows (A1:A500) in a spreadsheet and I just want to copy one by one row and then paste into another application and then press enter, loop should repeat this until finishes all 500 rows.
      I have looked at clipget(), clip(put() but dont know how to select next row in next turn. I also looked at Array to store but again no luck. Can some guide me please..