?
Solved

Send email confirmation from batch file

Posted on 2014-08-26
2
Medium Priority
?
1,466 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

0
Comment
Question by:eli290
2 Comments
 

Accepted Solution

by:
eli290 earned 0 total points
ID: 40286264
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
 
LVL 59

Expert Comment

by:Bill Prew
ID: 40286277
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month16 days, 20 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question