Вот пример, который я протестировал на моей стороне.
Вам нужно просто изменить переменную Sender
; Recipient
и SMTP_Server
@echo off
Title Send email notification if the URL is not live with BLAT
Color 0A
set "URLS=%~dp0URLS.txt"
If Not Exist "%URLS%" (
Color 0C & echo(
echo You should provide "%URLS%" with this batch file "%~nx0"
TimeOut /T 10 /NoBreak>nul
Exit
)
Set "Not_OK_URLS=%~dp0Not_OK_URLS.txt"
Set "BLAT=%~dp0blat.exe"
Set "LOG_BLAT=%~dp0LogBlat.txt"
If Exist "%Not_OK_URLS%" Del "%Not_OK_URLS%"
If Exist "%LOG_BLAT%" Del "%LOG_BLAT%"
Setlocal EnableDelayedExpansion
@for /f "delims=" %%a in ('Type "%URLS%"') do (
Call :StringFormat "%%a" URL
(ping -n 1 "!URL!" | findstr /r /c:"[0-9] *ms">nul) && (echo %%a is OnLine ==^> Success) || (echo %%a is Dead ==^> FAILURE)>>"%Not_OK_URLS%"
)
If Exist "%Not_OK_URLS%" Call :Mail
REM If Exist "%LOG_BLAT%" Start "" "%LOG_BLAT%"
Exit
::*************************************************************************************
:StringFormat <URL>
(
echo Function StringReplace(Str^)
echo Str = Replace(Str,"http://",""^)
echo Str = Replace(Str,"https://",""^)
echo StringReplace = str
echo End Function
echo wscript.echo StringReplace("%~1"^)
)>"%tmp%\%~n0.vbs"
for /f "delims=" %%a in ('Cscript /nologo "%tmp%\%~n0.vbs"') do ( set "%2=%%a" )
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
exit /b
::*************************************************************************************
:Mail
cls
Set Sender=-f changeme@yahoo.com
set Recipient=-to changeme@yahoo.com
set Subject=-s "Multi Ping URLS Tester and sending mail with BLAT"
set SMTP_Server=-server smtp.changeme.com
Set body=-body "App is Down, please find the attachment for the error logs"
set Message=-bodyF "%Not_OK_URLS%"
set Attachment=-attach "%Not_OK_URLS%"
set Log=-log "%LOG_BLAT%"
set Debug=-debug
echo.
echo Please Wait a While ... Sending Mail is in progress ......
%BLAT% %Sender% %Recipient% %Subject% %Message% %SMTP_Server% %Attachment% %Log% %Debug%>nul
Exit /B
::*************************************************************************************