Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


May 2005

Blat Goes the Message

Download this free command-line mailer
RSS
Subscribe to Windows IT Pro | See More Administration Tools Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

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 mark@mmco.com -f joe@bigfirm.com -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 joe@bigfirm.com 25 1
- joe swordfish

This command specifies the use of the mail.bigfirm.com SMTP server, the default sender's name as joe@bigfirm.com, 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.

End of Article



Reader Comments
Hi Mark,

Blat really is handy. One way I've put it to use it to mail NTBackup job logs (see "Want a Flexible Automated Backup Solution?" InstantDoc #44990). I just though I'd point out, though, that you don't need the .dll or the .lib files if you're just running blat.exe from the command line.

Regards,

Bill Stewart

AbqBill April 26, 2005 (Article Rating: )


Hi Mark,
I want to know if there is any way I can pass parameters to the subject of the email. For example, the subject should read "order no 123 has not been deliverd" where order_no is a variable.
I hope i've made myself clear. Any help would be appreciated.
Thanks,
Tahsin

tfathaulla November 28, 2005 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Battery Life Issues Almost Certainly Not Windows 7's Fault

While Microsoft is still investigating a notebook battery life issue that was supposedly caused by Windows 7, some interesting trends have emerged. ...

Confirmed: Battery Life Issues Not Windows 7's Fault

Microsoft on Monday issued a lengthy statement about the recent Windows 7 battery controversy, echoing my assessment from earlier in the day, but backing it up with hard, cold evidence. ...

Getting your iPhone to Sync with Exchange 2003

Follow these steps to use an iPhone with Exchange. ...


Windows OSs Whitepapers Protecting Microsoft SharePoint

Related Events Are your IT systems distributed? Or convoluted?

Deep Dive into Windows Server 2008 R2 presented by John Savill

The Easiest Way to Save Time and Money on E-mail and SharePoint Management

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2010 Penton Media, Inc. Terms of Use | Privacy Statement