#include <Array.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GUIConstantsEx.au3>
#include<file.au3>
;##################################
; Variables
;##################################
$SmtpServer = "smtp.mail.ru" ; адрес smtp-сервера вашей эл. почты
$FromName = "Иван Жуков" ; ваше имя
$FromAddress = "[email protected]" ; ваш почтовый адрес
$ToAddress = "На деревню дедушке.... Константину Макарычу" ; адрес получателя
$Subject = "Милый дедушка, Константин Макарыч!" ; тема
$Body = "Христом богом тебя молю, возьми меня отседа." ; содержание
$AttachFiles = ""
$CcAddress = ""
$BccAddress = ""
$Importance = "Normal"
$Username = "" ; логин
$Password = "" ; пароль
$IPPort = 25
$ssl = 0
Opt('GUIOnEventMode', 1)
Opt('TrayOnEventMode', 1)
Opt('TrayMenuMode', 3)
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
Global $sFile1 = @ScriptDir & '\1.txt', $hFile1, $sFile2 = @ScriptDir & '\2.txt'
Global $hGUI, $ListView, $hButt1, $hButt2, $hGUIState, $hExit
$hGUI = GUICreate('Список:', 619, 175, -1, -1)
GUISetBkColor(0xB9D1EA)
$ListView = GUICtrlCreateListView('|ASIN-10 |Price[New]|Price[Old]|SalesRank|Name|Date & Time', 5, 5, 609, 125, _
$LVS_NOSORTHEADER, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_HEADERDRAGDROP))
$hButt1 = GUICtrlCreateButton('Очистить список', 100, 140, 150, 25)
$hButt2 = GUICtrlCreateButton('Выйти из программы', 350, 140, 150, 25)
$hGUIState = TrayCreateItem('Отобразить/Скрыть Окно')
TrayCreateItem('')
$hExit = TrayCreateItem('Выход')
GUISetOnEvent($GUI_EVENT_CLOSE, '_CLOSEClicked')
GUICtrlSetOnEvent($hButt1, '_ListViewClear')
GUICtrlSetOnEvent($hButt2, '_Exit')
TrayItemSetOnEvent($hGUIState, '_CLOSEClicked')
TrayItemSetOnEvent($hExit, '_Exit')
GUISetState(@SW_HIDE)
$sFile1 = @ScriptDir & '\1.txt'
$sFile2 = @ScriptDir & '\2.txt'
$hTimer = TimerInit()
;считываем данные из файла в массив
$aFile1 = FileReadToArray($sFile1)
$aFile2 = FileReadToArray($sFile2)
;_ArrayDisplay($aFile2)
;получаем время изменения файла
$t1 = FileGetTime($sFile1, 0, 1)
$t2 = FileGetTime($sFile2, 0, 1)
$iStr = 0
While 1
If $t2 <> FileGetTime($sFile2, 0, 1) Then ; если 2.txt обновился начинаем сначала
$iStr = 0
$aFile2 = FileReadToArray($sFile2)
$t2 = FileGetTime($sFile2, 0, 1)
Else
EndIf
If $t1 <> FileGetTime($sFile1, 0, 1) And $t2 = FileGetTime($sFile2, 0, 1) Then
$aFile1 = FileReadToArray($sFile1)
$t1 = FileGetTime($sFile1, 0, 1)
For $i = 1 + $iStr To UBound($aFile1) - 1
$aTXT1 = StringSplit($aFile1[$i], @TAB, 2)
$aTXT2 = StringSplit($aFile2[$i], @TAB, 2)
If $aTXT1[3] < $aTXT2[3]/2 And $aTXT1[9] < 300000 Then
GUICtrlCreateListViewItem('|' & $aTXT1[0] & '|' & $aTXT1[3] & '|' & $aTXT2[3] & '|' & _
$aTXT1[2] & '|' & $aTXT1[1] & '|' & @MDAY & '/' & @MON & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC, $ListView)
GUISetState(@SW_SHOWNORMAL)
; отправка письма
$Subject = $aTXT1[0]
$Body = $aTXT1[0] & '|' & $aTXT1[3] & '|' & $aTXT2[3]
$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
$iStr += 1
Else
EndIf
Next
Else
EndIf
Sleep(100)
WEnd
Func _CLOSEClicked()
GUISetState(BitAND(WinGetState($hGUI), 2) ? @SW_HIDE : @SW_SHOWNORMAL)
EndFunc
Func _ListViewClear()
GUICtrlSendMsg($ListView, $LVM_DELETEALLITEMS, 0, 0)
EndFunc
Func _Exit()
Exit
EndFunc
; 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