#region AutoIt3Wrapper Precompiled parameters (common parameters)
#AutoIt3Wrapper_Icon=D:\ico\3444\ ;Icon, supports EXE, DLL, ICO
#AutoIt3Wrapper_OutFile=GetIp_Sendmail.exe;Output file name
#AutoIt3Wrapper_OutFile_Type=exe ; File Type
#AutoIt3Wrapper_Compression=4;Compression level
#AutoIt3Wrapper_UseUpx=y;Use compression
#AutoIt3Wrapper_Res_Comment= ;Comment
#AutoIt3Wrapper_Res_Description= ;Details
#AutoIt3Wrapper_Res_Fileversion= ;File Version
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=p; Automatic update version
#AutoIt3Wrapper_Res_LegalCopyright= ;Copyright
#AutoIt3Wrapper_Change2CUI=N; The program that modified the output is CUI (console program)
;#AutoItAutoIt3Wrapper_Res_Field=AutoIt Version|%AutoItVer% ;Custom resource segment
;#AutoIt3Wrapper_Run_Tidy= ;Script Organization
;#AutoIt3Wrapper_Run_Obfuscator= ;Code confusing
;#AutoIt3Wrapper_Run_AU3Check= ; Syntax Check
;#AutoIt3Wrapper_Run_Before= ;Before run
;#AutoIt3Wrapper_Run_After= ;After running
#endregion AutoIt3Wrapper Precompiled parameters (common parameters)
#include <file.au3>
#include <Inet.au3>
#include <Date.au3>
;Repeated runs are prohibited.
$g_szVersion = 'Get the external network IP and send it to the specified email'
If WinExists($g_szVersion) Then
Exit
EndIf
AutoItWinSetTitle($g_szVersion)
;Pallet Event
Opt("TrayOnEventMode", 1);Pallet event notification
Opt("TrayMenuMode", 1); Default menu item (Script Paused/Exit) will not be displayed.
TrayCreateItem("Send")
TrayItemSetOnEvent(-1,'_Sendmail')
$exititem = TrayCreateItem("Exit Program")
TrayItemSetOnEvent($exititem, "_Exit")
TraySetClick(16); The tray menu will be displayed only if the second mouse button is clicked (default right-click)
TraySetToolTip('Get the external network IP and send it to the specified email')
TraySetState()
Global $testIp
Global $oMyRet[2]
Global $oMyError = ObjEvent("", "MyErrFunc")
$s_ToAddress = IniRead(@ScriptDir & "\", 'Recipient', 'Recipient Address', '-1'); Recipient Address
$s_Subject = IniRead(@ScriptDir & "\", 'Recipient', 'Email Title', '-1');Email Title
TrayTip("Ready", "Recipient Address:" & $s_ToAddress _
& @CRLF & "Mail Title:" & $s_Subject, 5, 1)
_Sendmail();Send mail
AdlibRegister('_ReduceMemory', 1000 * 10); organize the memory once in 10 seconds
AdlibRegister('_Sendmail',1000*15)
While 1
Sleep(3000)
WEnd
Func _Exit()
Exit
EndFunc ;==>_Exit
;Send email=================================================================================================
Func _Sendmail()
$s_SmtpServer = "smtp." ;SMTP Server
$s_FromName = "" ; Email sender
$s_FromAddress = IniRead(@ScriptDir & "\", 'Sender', 'Email', '-1') ; Email sender's address
$s_ToAddress = IniRead(@ScriptDir & "\", 'Recipient', 'Recipient Address', '-1');"19377708@" ;Recipient Address
$s_Subject = IniRead(@ScriptDir & "\", 'Recipient', 'Email Title', '-1');"AU3 Email Send Test"; Email Title
Do
$Getip = _GetIP();Outdoor IP
Sleep(300)
TrayTip("Tip", 'Getting external network IP', 5, 1)
Until $Getip <> -1
If $testIp = $Getip Then
TrayTip("tip", 'The external network IP is the same as the last time I sent' & @CRLF & 'The program will not send it repeatedly.', 5, 1)
Return ;MsgBox(0,'',$Getip)
EndIf
$testIp = $Getip
$as_Body = "External Network IP:" & $Getip & @CRLF & "Send Time:" & _NowDate() & " " & _NowTime() ; Email Text; Get the external network IP
$s_AttachFiles = "" ; Attach address
$s_CcAddress = "" ;Cc address
$s_BccAddress = "" ; cc address
$s_Username = IniRead(@ScriptDir & "\", 'Sender', 'Email', '-1') ;Username
$s_Password = IniRead(@ScriptDir & "\", 'sender', 'password', '-1') ;password
$IPPort = 25; send port, the send port used by Gmail is 465
$ssl = 0
$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
_FileWriteLog(@ScriptDir & "\", "Email sending failed Error code:" & @error & " Description:" & $rc)
TrayTip("Email send failed", "Error code:" & @error _
& @CRLF & "Description:" & $rc, 5, 1)
Else
_FileWriteLog(@ScriptDir & "\", "The email was sent successfully Recipient address: " & $s_ToAddress & " Email title: " & $s_Subject & " Email text:" & $as_Body)
TrayTip("Email sent successfully", "Recipient address: " & $s_ToAddress _
& @CRLF & "Mail Title: " & $s_Subject _
& @CRLF & "Mail Text:" & $as_Body, 5, 1)
EndIf
EndFunc ;==>_Sendmail
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
$objEmail = ObjCreate("")
$ = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$ = $s_ToAddress
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $ = $s_CcAddress
If $s_BccAddress <> "" Then $ = $s_BccAddress
$ = $s_Subject
If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
$ = $as_Body
Else
$ = $as_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ","); File Divide
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
If FileExists($S_Files2Attach[$x]) Then
$($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
SetError(1)
Return 0
EndIf
Next
EndIf
$("/cdo/configuration/sendusing") = 2
$("/cdo/configuration/smtpserver") = $s_SmtpServer
$("/cdo/configuration/smtpserverport") = $IPPort
;Authenticated SMTP
If $s_Username <> "" Then
$("/cdo/configuration/smtpauthenticate") = 1
$("/cdo/configuration/sendusername") = $s_Username
$("/cdo/configuration/sendpassword") = $s_Password
EndIf
If $ssl Then
$("/cdo/configuration/smtpusessl") = True
EndIf
;Update settings
$
; Sent the Message
$
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
EndFunc ;==>_INetSmtpMailCom
; Com Error Handler
Func MyErrFunc()
$HexHexNumber = Hex($, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $ & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc
;End of sending the email================================================================================================================
; Organize memory
Func _ReduceMemory()
$I_PID = @AutoItPID
Local $ai_Handle = DllCall("", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $I_PID)
Local $ai_Return = DllCall("", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall('', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory