Send email from the command line
Two weeks ago, I wrote about backing up a remote windows machine using Remote Desktop.
One thing lacking from this solution is email notification. How do we know if the backup job started? Or finished?
There is a free and open source tool that can be used to solve this problem, it is called blat. It consists of an executable, and a DLL.
You can find it at http://www.blat.net/

Download it, and extract the files to a place where your scripts run. In my case, I put it in c:\backups
To start, you will need an SMTP server that you have access to. That is probably the most difficult part of getting it to work – which means it is very easy to use.
If I just want to send a simple email that tells me a batch script has started, I could call it like this:
blat.exe -f batch@intelliadmin.com -to support@intelliadmin.com -server 192.168.1.1 -subject "Batch file started" -body "The very important batch script has started"
You have five required options to get your email to send:
-f [FROM] (This is the email address that the message will come from)
-to [TO] (This is the email address the message will be sent to)
-subject [SUBJECT] (Subject of the email. Uses quotes if you have spaces)
-body [BODY] (Body of email. Use quotes if you have spaces)
-server [SERVER] (IP Address or host name of the server)
That is for a simple message. Blat is filled with powerful options. For example, I could run a robocopy in my script, and redirect the output to a text file like this:
robocopy c:\backup \\server\c\backup >> output.txt
Then, when I send my notification I could attach the output text file to my email like this:
blat.exe -f batch@intelliadmin.com -to support@intelliadmin.com -server 192.168.1.1 -subject "Batch file started" -body "The very important batch script has completed" -attach c:\backup\output.txt
Once the command runs, the output will show up as an attachment in my inbox:

Like I said, it is loaded with options. Check it out, and when you do just type blat.exe -help to get the entire list of command line parameters.
Written by Steve Wiseman on November 17th, 2009 with no comments.
Read more articles on BAT Files and otherSoftware and Tools and Utility.


















