Last modified: Jan. 2, 2016
Contents
1 - Summary
2 - Stunnel installation
3 - Blat installation
4 - Example batch file
1 - Summary
This guide will show how to send emails for system events using blat with
TLS/SSL capabilities in Windows. Blat is an SMTP client used to send emails.
This has been tested in Windows 7 on the x86 and x64 platforms.
2 - Stunnel installation
Stunnel can be downloaded at http://www.stunnel.org/. Modify the configuration
file at C:\Program Files\stunnel\config\stunnel.conf.
; **************************************************************************
; * Global options *
; **************************************************************************
client = yes
taskbar = no
; **************************************************************************
; * Service definitions (at least one service has to be defined) *
; **************************************************************************
[gmail-pop3]
client = yes
accept = 127.0.0.1:110
connect = pop.gmail.com:995
verify = 2
CAfile = ca-certs.pem
checkHost = pop.gmail.com
OCSPaia = yes
[gmail-smtp]
client = yes
accept = 127.0.0.1:25
connect = smtp.gmail.com:465
verify = 2
CAfile = ca-certs.pem
checkHost = smtp.gmail.com
OCSPaia = yes
Install stunnel as a service afterwards by selecting it from the Start Menu.
Start the stunnel service.
3 - Blat installation
Blat can be downloaded at http://blat.sourceforge.net/. Download and then
extract the files from the full directory to the Windows\system32 directory
for 32-bit operating systems and Windows\SysWOW64 directory for 64-bit
operating systems.
Open a command prompt and type the following commands. Here is an example that
uses a Gmail account which utilizes TLS on a 64-bit system.
> cd \
> cd %SystemRoot%\SysWOW64
> blat -installSMTP smtp.gmail.com testuser@gmail.com -u testuser@gmail.com -pw password - - -
> blat -profile
...
SMTP: smtp.gmail.com "testuser@gmail.com" 1 25 ******** ********
These commands will store the configurations in the Windows registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Public Domain\Blat
4 - Example batch file
Here is an example batch file that sends an email. This batch file also
requires some utilities from Cygwin (http://www.cygwin.com/).
@echo off
REM ####################################
REM Description: This script is used to test sending email notifications.
REM Required files: hostname, tr, blat
REM ####################################
REM ################
REM Set variables
REM ################
set PATH=%PATH%;C:\"Program Files"\"System Utilities"\bin\;C:\WINDOWS\SysWOW64\
set recipient=testuser@test.com
set profile=gmail.com
set server=127.0.0.1:25
for /f "tokens=*" %%x in ('hostname ^| tr "[:upper:]" "[:lower:]"') do (set host=%%x)
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 timestamp=%current_day% %current_time%
set subject="Test sent from %host% [%timestamp%]"
set body="This is a test."
blat -to %recipient% -subject %subject% -body %body% -p %profile% -server %server% -q > nul 2>&1
exit
|