Tip: Send a test log to your e-mail account using Blat

Being notified when a test plan completes can be very useful for those times when you’ll be a way from the test station but need to know when the test has finished. Luckily it’s very easy to send a test log by e-mail using ScanExpress tools and the free Blat command line mail utility. Using Blat, ScanExpress Runner can be configured to fire off an e-mail with a log file attached directly from a test step. In this article, we’ll go over how to configure Runner and Blat to send an e-mail after test execution.


Blat is a command line e-mail application for Windows systems. It can be used to send e-mail to an SMTP server and integrates well into systems that can call applications from the command line.

For Blat requirements and restrictions, see the Blat website and documentation at http://www.blat.net/.

One-time Setup for Each Station
Each station needs to have Blat installed and a few batch file parameters must be configured to be able to send mail. To set up each station:

  1. Install Blat to the desired location and modify the path to Blat.exe in the file mail0.bat.
  2. Modify mail0.bat to the correct email parameters.
  3. (Optional) Modify and copy computername.bat to C:local.

Test Procedure Setup
The test procedure can be configured to send e-mail by taking advantage of ScanExpress Runner’s ability to call command line applications from an ETF test step. To configure the test procedure to send e-mail:

  1. Add SendMailBlat.etf to the Runner test plan. It can be placed anywhere, but the last test step is the usual location.
  2. Copy mail.bat and mail0.bat to the directory where the ScanExpress Runner .TSP test plan is located.

Necessary Files
The following files are included in our example. The mailing function needs to wait for Runner to finish the test plan before it can send the complete log, so we use one batch file (mail.bat) to run and terminate while the second batch file (mail0.bat) polls until the test log file is ready.


  • Starts mail0.bat in a command window. Mail.bat closes, allowing Runner to finish the test and close the log file.
set showall=1
@echo on
@if not "%showall%"=="1" echo off
@echo mail.bat 4Sep2013

rem	Start batch file in a new command window. 
rem	This allows this batch file to complete.

START  mail0.bat



  • Waits until default.log is closed by Runner.
  • Runs Blat to email the default.log file, then closes the command window.
  • If multiple test stations are being run, it may be helpful to have a c:localcomputername.bat to include the station identification in the email subject.
set showall=1
@echo on
@if not "%showall%"=="1" echo off
@echo mail0.bat 4Sep2013

set attacht=default.log & REM attach text file(s) to message (filenames comma separated)

set app=C:WINAPPSEmailBlatblat.exe

set FeMail=support@corelis.com & REM From email address
set TeMail=support@corelis.com & REM To email address
set cc=support@corelis.com
set server=mail.corelis.com
set x="X-Header-Test: Email via Blat"
set debug=-debug -log blat.log -timestamp 

set subj="ScanExpress Runner test completed. %attacht% file attached"
if exist c:localcomputername.bat call c:localcomputername.bat 
if exist c:localcomputername.bat set subj="%computername% ScanExpress Runner test completed. %attacht% file attached."

@echo Wait until text log file %attacht% has been closed.
del $$$%attacht%

copy %attacht% $$$%attacht%
if not exist $$$%attacht% goto again

del $$$%attacht%

@echo Log file %attacht% has been closed and ready to be attached to the email.

@echo Send emial
rem	The first parameter for Blat is the file containing the body of the email. It is required.
%app% - -body "See attached log file" -to %TeMail% -cc %cc% -f %FeMail% -s %subj% -server %server% %debug% -x %x% -attacht %attacht%


rem	Exit command window.

computername.bat (Use of computername.bat is optional)

  • Sets an environment variable so that the test station name can be included in the subject line of the email.
  • It should be edited to use a name that identifies the test station, whether it is the computer name, a “Station #”, etc.
  • This is useful if there are multiple stations running.
  • This file allows mail0.bat to be the same for all test stations if the email parameters are the same.
  • If this file does not exist, an email will still be sent, but without a station name in the subject of the email.
set showall=1
@echo on
@if not "%showall%"=="1" echo off
@echo Computername.bat 4Sep2013
@echo localComputername.bat >> localbat_list.txt

set computername=Station 1



  • This file runs Mail.bat within a ScanExpress Runner test plan. Place this file at the end of a test plan to send a log after execution.
# Email a file 
# mail.bat starts mail0.bat in a command window. Mail.bat closes, allowing Runner to finish the test and close the log file..
# mail0.bat 
#	Waits until default.log is closed by Runner.
#	Runs Blat to email the default.log file, then closes the command window.
#	If multiple test stations are being run, it may be helpful to have a c:localcomputername.bat to include the station identification in the email subject.

RUN "Mail.bat"

Additional Notes

  • It may be desirable to disable the SendMailBlat.etf test step if the test is looped.
  • If the ScanExpress Runner log file filename is changed from the default “default.log“, mail0.bat must be modified to the correct log file name.

Command line execution from ETF steps is a great way to integrate addition functions into a ScanExpress Runner test plan. If you’re looking for notifications only when a test fails, try using Runner’s flow control features to run the SendMailBlat.etf step after certain conditions.

Share This Story, Choose Your Platform!