kylomas Posted January 31, 2015 Posted January 31, 2015 (edited) nitekram, I found a better example for you. The following code watches a log file for words contained in a "warn" file and sends an email if it finds any of the words. The code... expandcollapse popupHotKeySet('`', '_start_monitor') ; "`" to initiate manual scan HotKeySet('{ESC}', '_exit') ; ESC to stop script #include <array.au3> #include <date.au3> #include <File.au3> Local $file_monitored = @ScriptDir & '\log.txt' ; file to monitor Local $file_warn = @ScriptDir & '\warn.txt' ; file of words / phrases to check for Local $monitor_interval = 1 ; minute(s) between file check Local $bMonitor = False ; switch to start monitor local $oMyRet[2] ; array for error message from mail routine local $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; error routine local $aWarn, $aWarnO ; arrays for exceptions to scan for ; routine to start scan AdlibRegister('_start_monitor', $monitor_interval * 60 * 1000) ; main loop, will only initiate scan when the adlib routine sets the switch ; The exceptions file is read each time a scan is run so that it can be changed without stopping the script While 1 If $bMonitor = True Then _excp() _scan_file() $bMonitor = False EndIf Sleep(500) WEnd ; function to build array of exceptions in SRE format func _excp() $aWarn = StringSplit(FileRead($file_warn), @CRLF, 3) $aWarnO = $aWarn ; format WARN array for SRE usage Local $aTMP For $1 = 0 To UBound($aWarn) - 1 If $aWarn[$1] = '' Then ContinueLoop If StringLeft($aWarn[$1], 1) = ';' Then ContinueLoop If StringInStr($aWarn[$1], '&') Then $aTMP = StringSplit($aWarn[$1], '&', 2) $aWarn[$1] = '(?i)(.*?\Q' For $2 = 0 To UBound($aTMP) - 1 If $2 <> UBound($aTMP) - 1 Then $aWarn[$1] &= $aTMP[$2] & '\E(.*?)\Q' Next $aWarn[$1] &= $aTMP[$2 - 1] & '\E.*?)\R' Else $aWarn[$1] = '(?i)(.*?\Q' & $aWarn[$1] & '\E.*?)\R' EndIf Next endfunc ; scan routine and mail formatter Func _scan_file() Local $sTMP = '' ConsoleWrite(_Now() & ' >>>> Start scan' & @CRLF) Local $mon_file = FileRead($file_monitored) For $1 = 0 To UBound($aWarn) - 1 If $aWarn[$1] = '' Then ContinueLoop If StringRegExp($mon_file, $aWarn[$1]) Then ConsoleWrite(StringFormat('+ Found >> %-40s line = %-120s ', $aWarnO[$1], StringRegExp($mon_file, $aWarn[$1], 3)[0]) & @CRLF) $sTMP &= ' ' & StringRegExp($mon_file, $aWarn[$1], 3)[0] & @crlf EndIf Next if $sTMP then $sTMP = 'The following exception(s) ocurred:' & @crlf & @crlf & $sTMP ConsoleWrite('+ Sending mail...') _mailer($sTMP) ConsoleWrite(@error ? @crlf & '! Error sending mail = ' & $oMyRet[1] & @crlf : 'Send complete' & @CRLF) endif ConsoleWrite(_Now() & ' >>>> Scan Complete' & @CRLF) EndFunc ;==>_scan_file ; adlib to set switch that initiates scan Func _start_monitor() $bMonitor = True EndFunc ;==>_start_monitor Func _exit() Exit EndFunc ;==>_exit ; wrapper to set variables used in _INetSmtpMailCom Func _mailer($str) Local $SmtpServer = 'smtp.mail.yahoo.com' ; name of the yahoo smtp server Local $FromName = 'Me' ; what you want to appear in you inbox "From" column Local $FromAddress = 'kylomas010@yahoo.com' ; name of your yahoo account Local $ToAddress = 'kylomas@autoitscript.com' ; who you are sending the mail to Local $Subject = "Log File Exception Warning" ; title Local $Body = $str ; the body of the email Local $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Local $CcAddress = "" ; address for cc - leave blank if not needed Local $BccAddress = "" ; address for bcc - leave blank if not needed Local $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" Local $Username = 'kylomas010@yahoo.com' ; account username as known to the smtp server Local $Password = '********' ; password for the above account Local $IPPort = 465 ; GMAIL / YAHOO port used for sending the mail Local $ssl = 1 ; GMAIL / YAHOO enables/disables secure socket layer sending - put to 1 if using httpS $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then return seterror(1) EndFunc ;==>_mailer Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail = "" EndFunc ;==>_INetSmtpMailCom Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description, 3) ;ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1); something to check for when this function returns Return EndFunc ;==>MyErrFunc File to monitor = log.txt File with words / phrases to monitor for = warn.txt I hope this helps... kylomas edit: In case you are wondering, the loop timer delay was NOT implemented. This is run on demand by the hotkey. Whooops, I guess I did implement it... Edited January 31, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
nitekram Posted January 31, 2015 Author Posted January 31, 2015 (edited) I am getting ready to leave for the night...I will test Monday Night, but want to thank you for your time.EDITNevermind, I have like 10 mins - checking now Edited January 31, 2015 by nitekram 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
nitekram Posted January 31, 2015 Author Posted January 31, 2015 OK, I am going to test from my computer at home...it maybe like you said and not work do to firewall/gateway type issue. Not sure how many times it runs through this, but here is my output...sorry about the cause words 1/30/2015 11:32:54 PM >>>> Start scan + Found >> kill line = "Hi, my name is Talking Tina and I'm going to kill you." + Found >> fuck line = OK - Fuck You + Found >> ste^AL & documents line = Did you ste^al any of the documents that we asked for? + Found >> your & project & failure line = Oh, by the way, your last project was a complete failure! + Found >> tina line = "Hi, my name is Talking Tina and I'm going to kill you." + Sending mail... ! Error sending mail = The transport failed to connect to the server. 1/30/2015 11:33:15 PM >>>> Scan Complete 1/30/2015 11:33:54 PM >>>> Start scan + Found >> kill line = "Hi, my name is Talking Tina and I'm going to kill you." + Found >> fuck line = OK - Fuck You + Found >> ste^AL & documents line = Did you ste^al any of the documents that we asked for? + Found >> your & project & failure line = Oh, by the way, your last project was a complete failure! + Found >> tina line = "Hi, my name is Talking Tina and I'm going to kill you." + Sending mail... ! Error sending mail = The transport failed to connect to the server. 1/30/2015 11:34:15 PM >>>> Scan Complete I will have to look this code over, as I am not sure what the scan is doing yet. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
kylomas Posted January 31, 2015 Posted January 31, 2015 (edited) Yes, something is blocking you or you are not using an existing server/email name... Good Luck, kylomas edit: I sent you the code as it runs on my pc after testing it. The scan is not pertinent to your issue. Edited January 31, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
nitekram Posted January 31, 2015 Author Posted January 31, 2015 It has to be the company blocking, as I used your code, and just my username. But again, thanks for your time. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
kylomas Posted January 31, 2015 Posted January 31, 2015 (edited) and password?? edit: nevermind, I don't think you are even getting to authentication... Edited January 31, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
water Posted January 31, 2015 Posted January 31, 2015 (edited) Was looking at the outlook.au3 UDF ... I didn't read the whole thread but to use the OutlookEx UDF to send a mail on behalf of another user please have a look at the wiki. Edited January 31, 2015 by water 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
nitekram Posted January 31, 2015 Author Posted January 31, 2015 Thanks @water, I will look at that the next day I work. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator
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