Skip navigation

Blat Goes the Message

Download this free command-line mailer

In "Pulling the Event Trigger" (InstantDoc ID 44431), I introduced the eventtriggers.exe command, a Windows Server 2003 and Windows XP utility that lets you configure your computer to run a particular command when a certain event occurs. One action you can configure is to send yourself an email message about the event. Many readers wondered how they might send a message from the command line. The simple answer is to use a cool public-domain tool called Blat.

At the Blat site (http://www.blat.net), go to the Download page and download the Zip file under Blat Full Version. After the download is complete, open the Zip file and drill down through the folder structure until you find the \Full folder. Extract the three compressed files (i.e., blat.dll, blat.exe, and blat.lib) and place them on your system's path. (I put mine in the Windows directory.) You're now ready to use Blat.

Blat is a fairly complete SMTP client with a gaggle of options, but here's an example that will probably address your needs:

blat - -body "This is the message body" 
  -server mail.bigfirm.com 
  -to [email protected] -f [email protected] -subject 
  "Greetings from Joe!" -u joe
-pw swordfish

It's very important that you type this series of switches and arguments on one line. It looks monstrous, but you'll be able to preset a lot of those parameters.

What do those arguments mean? First, an email message needs a message body. Blat lets you specify the message text either in-line or as a separate file. To specify it in-line, type the message body just as the previous command's first line shows. Alternatively, you can presave the message text in a file—say, message.txt. The beginning of the command would then appear as blat message.txt. Note that the first argument Blat sees must either be a filename, which is the message body, or the hyphen surrounded by spaces and a -body parameter.

Second, messages typically have a sender's address, a receiver's address, and a subject line. The -to, -f, and -subject arguments provide that information. Every SMTP message needs a server to send it, and the -server option lets you configure that component.

Third, most modern SMTP servers are picky about who they'll send messages for. You either must send them from a local subnet or find some way to authenticate yourself. For example, if your SMTP server is a Microsoft Exchange Server 2003 system, you must authenticate for it to accept and send your mail, unless it's mail destined for that Exchange server. SMTP security varies tremendously. However, if you get a 550 error when you try to use Blat to send a message, it's almost certainly a matter of security. If you need to authenticate, the -u and -pwd options let you specify a username and password that Blat can use to authenticate you to the SMTP server. Unfortunately, Blat supports only the SMTP AUTH, AUTH PLAIN, and AUTH GSSAPI logon methods—not Microsoft's add-on AUTH NTLM logon method. Therefore, if you want to use Blat to send messages to a Microsoft SMTP server that requires authentication, you'll need to enable the Basic Authentication option on that SMTP server, and doing so might distress your security folks. But, again, if you're using Blat to automatically send messages to yourself or other local email accounts, you won't need to worry about authentication.

Most messages use the same settings for the SMTP server's name, the sender's email address, the TCP port number to use, the number of times to retry sending a message, and the username and password. With the following command, you can tell Blat to prestore this information in the registry:

blat -install <smtpserver> <senderaddress> 
  <portnumber> <nretries> - <logonusername>
<logonpassword>

For example, Joe in my earlier example could prestore his settings as follows:

blat -install mail.bigfirm.com [email protected] 25 1
- joe swordfish

This command specifies the use of the mail.bigfirm.com SMTP server, the default sender's name as [email protected], the use of TCP port 25 (the standard SMTP port), a retry interval of once, and authentication to the SMTP server as user "joe" with password "swordfish." You can, of course, use the aforementioned arguments to override any of these settings.

Blat is a sufficiently flexible tool that I use all the time. I schedule batch jobs late at night and have them email me status reports, I connect particular events with messages via Eventtriggers, and so on. If you take a few minutes to get accustomed to the syntax, you'll surely come up with even more great uses for it.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish