Send email confirmation from batch file

eli290
eli290 used Ask the Experts™
on
I have an xcopy batch job running and I would like to send myself a notification once it is completed. I am trying to use blat but cant seem to get it to work. Here is what I have so far. The backup job works fine no problem. I dont get any errors from the blat code but i dont get anything.

rem @echo off
set log=e:\shares\error.txt
xcopy E:\Shares\ y:\ /s /y /c /h > %log% 2>&1 && Goto 

AllOK

Echo %date% %time% There was an ERROR copying ACCT - Error %errorlevel% >>e:\shares\error.txt
C:\email\blat.exe -to mail@email.com

server servername -f mail@email.com -attach "e:\shares\error.Txt"

pause
exit /b

:allok

Echo %date% %time% There were no errors copying Fundbalance UB >>e:\shares

\fundbalance\fb\ub\backup\error.txt

set hostname=servername
set subject="Backup successful"
set toaddress=deliver-email-mail@email.com
set attach=e:\shares\error.txt


pause
exit /b

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Figured it out... Used this instead
set SERVER=127.0.0.1
set TO=TO_PERSON_1,TO_PERSON_2
set CC=CC_PERSON_1,CC_PERSON_2
set SUBJECT="A fanciful subject!"
set BODY="Oh yes my dear lad!"
blat -server %SERVER% -to %TO% -cc %CC% -subject %SUBJECT% -body %BODY%

Open in new window

Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
If that is the actual file there seem to be some extra line feeds where they shouldn't be.

Take a look at the following link for some examples and info on blat (thanks Steve!).

http://scripts.dragon-it.co.uk/links/email-from-batch?OpenDocument

As far as the line feeds go I think it should look more like this, although I'm not sure if you are trying to send an email on both success or failure?

rem @echo off
set log=e:\shares\error.txt
xcopy E:\Shares\ y:\ /s /y /c /h >"%log%" 2>&1 && Goto :AllOK

Echo %date% %time% There was an ERROR copying ACCT - Error %errorlevel% >>"%log%"

C:\email\blat.exe -to mail@email.com server servername -f mail@email.com -attach "%log%"

pause
exit /b

:allok

Echo %date% %time% There were no errors copying Fundbalance UB >>e:\shares\fundbalance\fb\ub\backup\error.txt

set hostname=servername
set subject="Backup successful"
set toaddress=deliver-email-mail@email.com
set attach=e:\shares\error.txt

pause
exit /b

Open in new window

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial