major098 Posted March 27, 2022 Share Posted March 27, 2022 (edited) Hello I'm using a script to check changes in a folder "mail". expandcollapse popup#include <File.au3> #include <Constants.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Math.au3> #include <array.au3> #NoTrayIcon Opt("TrayMenuMode", 1) TraySetState() TraySetToolTip("File List Auto-Update") TrayTip("File List Auto-Updater Loaded Succesfully!", "This program will check for changes on the folder specified, and will Auto-update the List of files in the specified folder into the file: songs.txt * Software Created By SeeR *", 5, 1) ;Explicitly declaring variables and descriptive names are always a good idea Global $sConfigPath = @ScriptDir & "\config.ini" ;changed to ini format as the filewriteline was too much trouble when changing the values. Local $CtrlHowTo = TrayCreateItem("How to configure") ;technically all these are global too, but I don't use them that way, so I use Local (Local only exists in functions) Local $CtrlFileName = TrayCreateItem("File Name") Local $CtrlSelectFolder = TrayCreateItem("Select Folder") Local $CtrlReset = TrayCreateItem("Reset Config_data") Local $CtrlAbout = TrayCreateItem("About") Local $CtrlExit = TrayCreateItem("Exit") Local $nInterval = 500 ;check for changes every 500 ms Global $total Global $sFolderPath = IniRead($sConfigPath,"Paths","Folder","") If Not FileExists($sFolderPath) Then $sFolderPath = _SetFolder() ;moved this to a func, so it can be called again when changing the path EndIf Global $sFilePath = IniRead($sConfigPath,"Paths","File","") If $sFilePath = "" Then $sFilePath = _SetFile() ;also so it can be called again EndIf Global $hListFile = FileOpen($sFilePath,1) ;fileopen if you want to write more then once Global $aLastFileList = _FileListToArray($sFolderPath) ;completely did away with the check functions If Not IsArray($aLastFileList) Then Local $aLastFileList[1] = [0] ;in case the folder is empty AdlibRegister("_CheckChanges",$nInterval) ;I don't want to slow the main loop down, and I don't want to check for changes every few MS, so I use this While 1 Switch TrayGetMsg() Case 0 ContinueLoop Case $CtrlAbout MsgBox(0, "About", "This software is created by SeeR * © by SeeR * Feel free to use, but don't take the credits for it.") Case $CtrlExit FileClose($hListFile) AdlibUnRegister("_CheckChanges") Exit Case $CtrlSelectFolder $sFolderPath = _SetFolder() ;this is why I created the _SetFolder function Case $CtrlFileName $sFilePath = _SetFile() Case $CtrlHowTo MsgBox(0, "Configuration", "To configure this program correct you need to do the following things: " & @CRLF & "If you already tried to configure, reset the configuration data (click on the programs icon down in right corner)" & @CRLF & "1. Select what folder is going to be checked" & @CRLF & "2. Select the filename for the saved file List (IMPORTANT: you MUST add .txt after the filename when you save" & @CRLF & "3. Don't delete the file 'config.txt'. If you move the .exe file, also move the 'config.txt'" & @CRLF & @CRLF & "Enjoy! © by SeeR") Case $CtrlReset If FileExists($sConfigPath) Then FileDelete($sConfigPath) TrayTip("File List Auto-Update", "Config succesfully reset!", 2, 1) $sFolderPath = _SetFolder() ;or exitloop here, whatever you like. $sFilePath = _SetFile() Else MsgBox(0, "Config file not found!", "The config file needed by file List Auto-Updater could not be found!" & @CRLF & "The file may have been moved, or just not created yet - please follow the instructions and try again") EndIf EndSwitch WEnd Func _CheckChanges() Local $sChangeList, $sMessage Local $aNewFileList = _FileListToArray($sFolderPath) $aNewFileList2 = _FileListToArray If @error Then Local $aNewFileList[1] = [0] EndIf ;check for deleted files For $i_1 = 1 To $aLastFileList[0] For $i_2 = 1 To $aNewFileList[0] If $aLastFileList[$i_1] == $aNewFileList[$i_2] Then ContinueLoop 2 ;this file still exists EndIf Next ;if the script reaches this line a file has been added $sChangeList &= "Deleted file: " & $sFolderPath & "\" & $aLastFileList[$i_1] & @CRLF ;add to the changelist $sMessage &= "Deleted file: " & $aLastFileList[$i_1] & @CRLF ;small format for the popup Next ;check for added files For $i_1 = 1 To $aNewFileList[0] ;loop through For $i_2 = 1 To $aLastFileList[0] If $aNewFileList[$i_1] == $aLastFileList[$i_2] Then ContinueLoop 2 ;this file already existed EndIf Next Sleep(1000) $sTextFile = $sFolderPath & "\" & $aNewFileList[$i_1] $aas = FileReadLine($sTextFile,2) $ass2 = "mail1" If $aas = $ass2 Then $aas3 = FileReadLine($sTextFile,1) Else $aas3 = FileReadLine($sTextFile,1) EndIf ;~ ;if the script reaches this line a file has been added $sChangeList &= "Added file: " & $sFolderPath & "\" & $aNewFileList[$i_1] & @CRLF ;add to the changelist $sMessage &= "Added file: " & $aNewFileList[$i_1] & @CRLF ;small format for the popup Next If $sChangeList Then ;personal preference to have just the one message ;~ TraySetState(4) ;~ TrayTip("File List Auto-Update", "File List is now Auto-updating...", 2, 1) FileWrite($hListFile, $sChangeList) TrayTip($sFilePath, $sMessage, 2) ;~ TraySetState(8) ;~ TrayTip("File List Auto-Update", "File List has been updated succesfully!", 2, 1) $aLastFileList = $aNewFileList ;we've checked everything, so the new array is not the old array. EndIf EndFunc Func _SetFolder() Local $sPath Do $sPath = FileSelectFolder("Select folder to check for files", "", 1) Until FileExists($sPath) IniWrite($sConfigPath,"Paths","Folder",$sPath) Return $sPath EndFunc Func _SetFile() Local $sPath Do $sPath = FileSaveDialog("Select name of the file List file", "", "File_List Text file (*.txt)", 2) Until $sPath If StringRight($sPath,4) <> ".txt" Then $sPath &= ".txt" EndIf IniWrite($sConfigPath,"Paths","File",$sPath) Return $sPath EndFunc Script waiting for a .txt file with e-mail, there's can be only two e-mails a@a.com or b@b.com, what I'm trying to do is implement to it: expandcollapse popup$SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "" ; name from who the email was sent $FromAddress = "" ; address from where the mail should come $ToAddress = "" ; destination address of the email - REQUIRED $Subject = "" ; subject from the email - can be anything you want it to be $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS ;$IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS ;################################## ; Script ;################################## Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF 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 ; ; ; Com Error Handler 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 So if e-mail "A" it will send email from "A" , else it will use B, problem is that I getting error with no matching function "Endfun" when I trying to use it in if and else. Could anyone help please? Thank you. Edited March 27, 2022 by major098 Link to comment Share on other sites More sharing options...
major098 Posted March 27, 2022 Author Share Posted March 27, 2022 (edited) If $aas = $ass2 Then $aas3 = FileReadLine($sTextFile,1) Else $aas3 = FileReadLine($sTextFile,1) EndIf I'm trying to implement it here. $aa3 is a e-mail "a@a.com' else to send from email 'b@b.com' Edited March 27, 2022 by major098 Link to comment Share on other sites More sharing options...
jchd Posted March 27, 2022 Share Posted March 27, 2022 (edited) Your test serves no purpose since you perform the same action in both branches. I don't get what you mean with "Endfun". What does the console tell when you get that error? Also: tidy your scripts! Edited March 27, 2022 by jchd Earthshine 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
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