Automatically send email with blat
A very common question we get about MyTrigger is the question about sending emails from MyTrigger. To send email, MyTrigger needs the help of an external tool, and what we recommend is Blat. Blat is a free win32 command line program for sending email. It’s very small, very easy to use and in our experience very reliable. Here’s the blat installation instructions from their own readme:
1) Copy the file “Blat.exe” to your “WINNT/SYSTEM32
directory, or to any other directory in your path.
2) Optionaly, run:
“Blat -install smtp.yoursite.tld youruserid@yoursite.tld”
As you can see, it’s extremely easy to get started with blat. After that, your good to go. To send an email from a command line script, all you do is run:
blat filetosend.txt -to someone@somewhere.com /
-subject “testing blat”
We’re running an automatic build system. It’s running one of our servers and automatically builds the entire MyTrigger product on a schedule and manually whenever needed. The end result is that a new folder is created with a name like “//buildhost/builds/MyTrigger_1.5.102.0?.
Then we have another computer that is running smoke tests on new builds, we want to avoid installing any developer tools on the test machine since that would make the machine rather unrepresentative for what our users would normally run. The test computer is running a known stable version of MyTrigger that watches the /builds folder on the build machine. Whenever a new build is ready, MyTrigger detects that and can launch the smoke tests. For sanity, the stable version of MyTrigger is shut down during this test and turned back again afterwards, but that’s a condition that should be considered rare :-)
Once the smoke tests are done, the script sends an email using blat to notify that the build is done and the result of the smoke test.
Configuring MyTrigger to do this for us is actually pretty simple. Here’s how:
1) Create the script that should run when the trigger fires:
REM I’m using forward slash instead of backslash due to
REM a feature in Wordpress that I’ve left alone.
REM ************************************************
REM Start the smoke test, it’s logfile is in
REM /tests/runtests.log
REM ************************************************
call \tests\runtests.cmd
REM **************************
REM Email the log
REM The -tf switch tells blat to look
REM in the specfied file for the recepients
REM ***************
blat \tests\runtests.log -tf recepients.txt /
-subject “logfile for %date% %time%”
2) Configure MyTrigger to listen to the interesting folder. Bring up the MyTrigger UI, go to the Folders tab and press “Add". Type the path to the Folder to watch, note that it’s OK to watch UNC (network) folders as long as the underlying file system in NTFS. I check the “Watch subfolders” checkbox since what I’m waiting for is files to be added in a new subfolder. I’m using a *.txt wildcard filter since I know that in my specific case, the last thing that gets copied to the build folder is a buildlog.txt. I choose to only have MyTrigger react when a file or folder is added. At last I type the name of the batch script we just created and press save. There, the trigger is done!
As you can see, blat and MyTrigger helps creating a powerful, time saving solution that’s less prone to error that the manual alternative. Just the way we want it.