Packetwatch.net

Email notifications using Blat in Windows



Last modified: May 25, 2010

Contents
1 - Summary
2 - Blat installation
3 - Example batch file


1 - Summary

This guide will show how to send emails for system events using blat in
Windows. Blat is an SMTP client used to send email. This has been tested in
Windows NT4, 2000, XP, 2003 and 2008.


2 - Blat installation

Blat can be downloaded at http://blat.sourceforge.net/. Download and then
extract the files to the Windows system32 directory. Open a command prompt and
type the following commands.

Install
These commands will store the configurations in the Windows registry. HKEY_LOCAL_MACHINE\SOFTWARE\Public Domain\Blat 3 - Example batch file Here is an example batch file that sends an email. For Windows NT4 it's slightly different. This batch file also requires the Windows port of the UNIX date command. @echo off set hostname="C:\WINNT\system32\hostname.exe" %hostname% > %hostname_results%# for /f "tokens=1" %%x in (%hostname_results%#) do (set host=%%x) del /f /q # > nul 2>&1 date /t > %date_results%# for /f "tokens=2" %%x in (%date_results%#) do (set date=%%x) del /f /q # > nul 2>&1 set month=%date:~0,2% set day=%date:~3,2% set year=%date:~8,2% set current_day=%month%/%day%/%year% set unix_date="C:\Program Files\System Utilities\bin\date.exe" %unix_date% > %unix_date_results%# for /f "tokens=4" %%x in (%unix_date_results%#) do (set unix_date=%%x) del /f /q # > nul 2>&1 set hour=%unix_date:~0,2% set minute=%unix_date:~3,2% set second=%unix_date:~6,2% set current_time=%hour%:%minute%:%second% set blat="C:\WINNT\system32\blat.exe" set recipient="testuser@test.com" REM set recipient="testuser1@test.com,testuser2@test.com" set profile="test.com" set body="This is a test." set subject="Test sent from %host% [%current_day% %current_time%]" %blat% -to %recipient% -subject %subject% -body %body% -p %profile% -q > nul 2>&1 exit This batch file is for Windows 2000, XP, 2003 and 2008. For Windows 2000, you will need to change the hostname and blat variables to point to C:\WINNT\system32. @echo off set hostname="C:\WINDOWS\system32\hostname.exe" %hostname% > %hostname_results%# for /f "tokens=1" %%x in (%hostname_results%#) do (set host=%%x) del /f /q # > nul 2>&1 set month=%date:~-10,2% set day=%date:~-7,2% set year=%date:~-2,2% set current_day=%month%/%day%/%year% set hour=%time:~-11,2% REM put a leading zero for hours before 10 AM if "%time:~0,1%"==" " set hour=0%hour:~1,1% set minute=%time:~-8,2% set second=%time:~-5,2% set current_time=%hour%:%minute%:%second% set blat="C:\WINDOWS\system32\blat.exe" set recipient="testuser@test.com" REM set recipient="testuser1@test.com,testuser2@test.com" set profile="test.com" set body="This is a test." set subject="Test sent from %host% [%current_day% %current_time%]" %blat% -to %recipient% -subject %subject% -body %body% -p %profile% -q > nul 2>&1 exit

Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2024.