We help IT Professionals succeed at work.

Send email confirmation from batch file

1,868 Views
Last Modified: 2014-08-26
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

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
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
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.