Page 1 of 1

automatically send an email

Posted: 09 Apr 2019 00:54
by philiphill
I write an internet connection test program via file batch , and every time lose the network connection, it will automatically send an email to my gmail,The problem is the program will send an email continuously until it is connected again,It is very troublesome,so I want the program to send email once.

Code: Select all

set /p host1= "Please Input IP: "
set logfile=%host1%.log


echo DEST = %host1% > %logfile%

:Ping
ping %host1% -w 1000 -n 10  >> %logfile%
IF '%ERRORLEVEL%'=='1'  GOTO SEND_MAIL
timeout 1 > NUL
GOTO Ping
:SEND_MAIL
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -file send_mail.ps1
GOTO Ping

Re: automatically send an email

Posted: 09 Apr 2019 04:56
by penpen
If you don't want to loop after sending the mail, then why do you loop using "GOTO Ping"?
You could just remove it.


penpen

Re: automatically send an email

Posted: 09 Apr 2019 22:29
by philiphill
Dear penpen ! If removed "GOTO Ping" the network check process will end when it sends me a mail to my gmail.I want the network testing process to take place continuously and without interruption.

Re: automatically send an email

Posted: 10 Apr 2019 06:16
by penpen
Then that might help you:

Code: Select all

set /p host1= "Please Input IP: "
set logfile=%host1%.log


echo DEST = %host1% > %logfile%

:Ping ^
timeout 1 > NUL
ping %host1% -w 1000 -n 10  >> %logfile%
IF '%ERRORLEVEL%'=='1'  GOTO SEND_MAIL
GOTO Ping
:SEND_MAIL
PowerShell.exe -NoProfile -ExecutionPolicy Bypass -file send_mail.ps1

:wait untill connected
ping %host1% -w 1000 -n 10  >> %logfile%
IF '%ERRORLEVEL%'=='0'  GOTO Ping
timeout 1 > NUL
GOTO wait
penpen