:: Created By Joe Davis :: joe@josephmdavis.com :: This script will email the latest backup logfile to a specified user or group. @echo off :: Name this script SET _SCRIPTNAME= :: Define backup logfile parameters set _LOGLOCATION= set _Text2Mail=%systemdrive%\bmailtext.txt :: Define bmail parameters :: EXELOCATION is the location of the BMAIL Executable. set _EXELOCATION=\\filesrv01\tools set _SMTPSERVER=somerelay.com set _TOADDR= set _FROMADDR= set _SUBJECT="Backup Log for %_SCRIPTNAME%" :: Find most recent logfile. :: Using the /od option of the DIR command lists the files in the order they were last modified, newest being on the bottom. :: The /b option removes any other formatting from the output of the DIR command. for /f %%j in ('dir "%_LOGLOCATION%\backup*.log" /od /b') do set _currentLog=%%j :: Because of the formatting of the logfile, not all email programs render it properly. :: Therefore we output the contents of the logfile to a plain ASCII text file. type "%_LogLocation%\%_CurrentLog%" >> %_Text2Mail% :: Send our email using the ASCII text file generated above as the message body. %_EXELOCATION%\bmail -s %_SMTPSERVER% -t %_TOADDR% -f %_FROMADDR% -a %_SUBJECT% -m "%_Text2Mail%" -c :: Delete our text file del %_Text2Mail%