Send email confirmation from batch file

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

eli290Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

eli290Author 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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bill PrewCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.