Last month I’ve written an article on executing any file when application crashed or stopped running. All I need is a small portable software that monitors for a process availability. When the process crashed, the monitoring software will automatically run a batch file containing a few more commands to run. A game server with intensive mod can cause daily random crashes and it’s important to make sure that it auto restarts the game server when that happens. So far everything is working as expected except it’d have been better if I can include an email or SMS notification when the server crashes.
![]()
In order to do that, I found a small portable tool called Blat which can send an email using command line. Blat is a Win32 command line utility that sends eMail using SMTP or post to usenet using NNTP. Command line application is very different from graphical user interface (GUI). In programs with GUI, there are buttons and boxes for you to enter the details but for command line, everything must be typed out in a single line. It’s not so user friendly but very flexible.
To use Blat to send email, you will definitely need to refer to the syntax manual. Below is an example for a normal SMTP server that requires authentication. You can also use IP:Port for -server syntax. By default Blat uses port 25 but if your SMTP server uses a different port, then you can change it.
blat.exe -f from@email.com -to recipient@email.com -subject ThisIsTheSubject -body ThisIsTheBody -server smtp.server.com:25 -u SMTPUserLogin -pw SMTPUserPass
Using the command line above, I will receive an email notification alert whenever the server goes down. If I want to receive it in a form of SMS on my mobile, I will need subscribe “email to SMS” service from Clickatell, World-Text or any other provider that offers such service.
There hasn’t been any updates on Blat for more than 2 years but I can verify that it works without any problems on my webhosting SMTP server. However I don’t think you can use Gmail, Hotmail, and Yahoo SMTP to send out email because this 3 email service requires SSL and I can’t find this option in Blat. You can try SendEmail which supports TLS but you will first need to install the Net::SSLeay and IO::Socket::SSL perl modules on Windows.
[ Visit Blat Official Homepage ]
Related posts:
I know this is an old post, but i wanted to share an app that I wrote specifically for this reason: SwithMail – you can get it at swithmail.tbare.com
I’m currently working on version 2 which has XML support and a tool to generate your CLI string for you, taking the guess work out of it.
Love the blog – keep up the good work!
@ raymond
You can use blat with gmail, but this is more advance.
You need to use stunnel locally to do the secure link.
Here is my batch file example
*================================
@echo off
setlocal enableextensions enabledelayedexpansion
:: Startup directory where the command is
cd /d %~dp0
:: Configure Email Options
SET emailfrom=xxx@gmail.com
SET emailto=xxx@gmail.com
SET password=yyyyy
SET SMTPserver=127.0.0.1:465
stunnel\stunnel.exe -install -quiet
net start stunnel >nul
::sendfiles
blat\blat.exe test-email.txt -q -s “testing 1 2 3″ -base64 -to %emailto% -f %emailfrom% -u %emailfrom% -pw %password% -server %SMTPserver%
:cleanup
:: Stop stunnel
net stop stunnel >nul
stunnel\stunnel.exe -uninstall -quiet
:: Delete vars
SET emailfrom=
SET emailto=
SET password=
SET SMTPserver=
rem exit
pls provide me the bit defender key
nice info,…thanks Ray
great.. i can use this for my visual basic project. thanks.
nice info raymond..:-)..tq