Solved

Multiple line output from command line in SMTP

Posted on 2010-09-06
16
418 Views
Last Modified: 2012-05-10
I am not sure how to word this.
i am using a command line SMTP client to send a log file as a email. the utility is bmail.
http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm

bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -b "Start time:%StartTime% End Time:%EndTime%" -m "%Logfile%"

The part:  -b "Start time:%StartTime% End Time:%EndTime%"
The output it is giving is Start time:16:27:18.77 End Time:16:28:03

I want it to be:
Start time:16:27:18.77
End Time:16:28:03

How do i get it to return to the next line between the 2 parts?
0
Comment
Question by:tsukraw
  • 7
  • 3
  • 3
  • +1
16 Comments
 
LVL 21

Assisted Solution

by:AmazingTech
AmazingTech earned 166 total points
ID: 33615393
I don't think you can with the -b parameter. Perhaps you can create a text file and then use the -d.

echo Start time:%StartTime%>Body.txt
echo End Time:%EndTime%>>Body.txt

bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -d Body.txt  -m "%Logfile%"
0
 

Author Comment

by:tsukraw
ID: 33615400
-d is debug?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616383
I think he means -m,

Steve
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 167 total points
ID: 33616406
And I don't know what happened to the code segment I attached there, typing in directly this time... just creates a new file in temp with your log details then the original log file.

Steve

set log="%temp%\logfile.txt"
echo Start time:%StartTime%>%log%
echo End Time:%EndTime%>>%log%
echo. >> %log%
type %logile% >%log%
bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -d Body.txt  -m "%Log%"
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616409
Sorry forgot to change the last time second time around:
set log="%temp%\logfile.txt"
echo Start time:%StartTime%>%log%
echo End Time:%EndTime%>>%log%
echo. >> %log%
type %logile% >%log%
bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%"  -m %Log%
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616417
I blame EE not accepting it first time around .... try changing

type %logile% >%log%


to
type %logfile% >>%log%

too!

Steve
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 33616687
I believe the piece that Tucker may not have shared is that the log file he is already attaching is generated out of a utility program, so that file needs to be attached, and can not be pre-pended to.  In addition to having that file attached, he wants a multiline body.

It doesn't look like bmail accepts multiple -m files so not sure how to solve this?

~bp
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616707
That is why I was (trying) to suggest creating the new text and then Appending the old file to the end and attaching that one instead.

Personally I tend to use blat.exe for mailing though have had to use bmail.exe for some people and can't think of another way at the moment short of using one of the MIME body encoding progs to make a body and attach it.

Steve
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 33616740
Gotcha Steve.

~bp
0
 

Author Comment

by:tsukraw
ID: 33616782
So overall the solution would be to have the script create a new log file with the content I want and join the utilities output log int it?  
outputting the content I want to a file is simple enough but how do I join the other file into it?
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 167 total points
ID: 33616905
Tucker,

I think the resultant script would look like this.

Notice that we capture the output of the backup to a temporary log file (log.txt) and then after writing the begin and end header lines to the real log file we add on the output of the backup command.  Then that is what we email.

Make sense?

~bp
@echo off
set Day=%DATE:~10,4%_%DATE:~4,2%_%DATE:~7,2%
set CurrentDir=%~dp0
if "%CurrentDir:~-1%"=="\" set CurrentDir=%CurrentDir:~0,-1%
set Logfile=%CurrentDir%\BackupLogs\G-Drive-%Day%.txt
 
echo Start Time:%TIME%>"%Logfile%"
 
wbadmin start backup -backupTarget:G: -include:F: -quiet > "%TEMP%\log.txt"
 
echo End Time:%TIME%>>"%Logfile%"
echo.>>"%Logfile%"
type "%TEMP%\log.txt" >>"%Logfile%"
 
for /F "usebackq tokens=*" %%A in ("emailaddy.txt") do (
  bmail -s localhost -t %%A -f backup@severname -h -a "Backup Report - %Date%" -m "%Logfile%"
)

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33617154
Didn't know this was a follow up Bill.  

See post 33616409 / 33616417 above :-)

Steve
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 33629303
Sorry, I was replying on my iPhone so the -d should have been the -m but also include the log file like how dragon-it explained it.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 34080713
Accept billprew http:#33616905.
Assist dragon-it http:#33616409
and AmazingTech http:#33615393
0
 

Author Closing Comment

by:tsukraw
ID: 34089452
Really no solution with this app.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now