Easily Send Command Line Emails with Blat

Ryan Dube 12-01-2012

Blat. Not exactly the word you envision would be the name of a tool that you can use to send out emails to anyone in the world, from any application or software tool that you desire. It more sounds like the sound that a raw egg makes when it hits the floor.


Well, that’s exactly what I’m going to introduce to you today, if you’ve never heard of it before. Blat is not new, but it’s important. There are numerous applications and utilities that will automatically send email notifications out for you.

You can get RSS news updates automatically emailed. You can have websites send you email notifications, like the 10 notification sites 10 Alert & Notifier Websites to Keep Track of Stuff You Might Otherwise Miss Read More that Saikat covered. You can even set up services like Google Analytics How To Put Google Analytics to Work for You With Email Reports Read More to send you automatic reports every now and then.

But what if you want to set up batch jobs or Windows scripts on your own computer where you can send out emails straight from the command line? Well, Blat is a Win32 utility that you can use to send emails via SMTP straight from the command line.

Setting Up Blat Command Line Emails

Blat is a free utility that’s been available ever since Windows 95, and it has continued to evolve through the years. It is now available as a SourceForge offering.

While Unix users have utilities like sendmail to issue command line emails, Windows users have turned to Blat since Windows 95 to do the same. Many computer users don’t realize how easy it can be to send emails via the command line in Windows, only because they’ve never tried blat. So, for those of you that have never seen it, I would like to introduce you to this brilliantly simple, yet powerful command line utility.


After you download and extract the Blat files, you’ll find blat.dll, blat.lib and blat.exe. Make sure to place them all in one folder, and you can launch the .exe file from there.

The first step is to issue the “install” command which will tell blat what SMTP server and account to use.

blat command line email

In this case, the command I issued was “blat -install <smtp server> <email user id>”


This works for my SMTP account (no password required), but if yours requires authentication, you can include “-u <username> -pw <password>”, but keep in mind that blat still doesn’t support SSL without some third party tool, so it won’t work at this time with Gmail SMTP.  Once you’ve got the id/pw and smtp server to use installed, you can issue the blat command at any time from the command line.

In my example, I have  a file stored in the blat directory called help.txt that contains all of the blat command parameters. I want to email this text file as the email body using blat. I can do this in one command by typing “blat help.txt -to <email address to send to> -subject TestFile”

That’s it!

blat command line email utility


This command opens up the test file, embeds it as the email body, uses the subject line that you’ve defined (don’t use any spaces though), and then sends the email to the recipient you defined. Here’s what the email looked like when I received it.

Easily Send Command Line Emails with Blat blat31

While being able to open up a command prompt and issue a quick email like this is pretty cool, it’s even cooler to use that ability from within an even more powerful Windows Script.

Issue The Blat Command From Within A Windows Script File

My goal in this example is fairly simple. I have a Windows Script that pings a list of websites that I have listed in a text .ini file.


blat command line email

Currently, when the script encounters a problem pinging any of the sites, it’ll issue an alert window that looks like this.

Easily Send Command Line Emails with Blat blat5

Instead, I’m going to improve my script by issue an email whenever a website isn’t pingable, rather than depending on a pop-up window. To do this, I’m just going to add the following section to my existing Windows Script.

'If any ping failed, send an email

If Ping = false then
        '* Send out email
	wscript.echo "Sending " & strFailedList "c:\temp\blat\blat.exe -body " & strFailedList & " -to -subject TestFile"

End If

If you’ve never used scripting in WSF before, you have to issue the command “Set Shell = wscript.createObject(“”)” to set it up. Then you can use as show above to launch the blat.exe command.

A few hard lessons learned about blat limitations. The command above only works if the string variable ‘strFailedList’ has no spaces in it. To accomplish this I use a dash between each failed IP ping, so my final email looks like this.

Easily Send Command Line Emails with Blat blat6

If you want a better formatted email, you could always output any messages that you want to email out into an output file, and then replace the “-body” parameter with the name of the file instead (like the example I showed in the first half of this article).

As you can see, the blat tool lets you integrate email sending into your Windows Scripts, and opens up the possibility of all sorts of useful email notifications for when things go wrong with your PC.

If you’ve never tried it before, give the Blat tool a test and let us know what you think. Did you come up with any creative uses for it in your Windows scripts? Share your ideas and insight in the comments section below.

Image Credit: ShutterStock

Related topics: Batch Image Editing, Email Tips.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Donald John
    March 30, 2016 at 5:10 pm

    Can SwithMail send message bodies whose source file is not text, but a form of html or a Word format?

    • joesmith
      March 31, 2016 at 10:13 am

      Mail Alert Simple Mailer can do it for sure.

    • Tim
      July 25, 2016 at 9:23 pm

      Hey - I wrote SwithMail. :)

      SwithMail will allow you to specify a document to send as the body. While I can't say I've ever tried a word doc, I have done HTML files for sure.

      I know this message was a bit late, but thought I'd answer in case others had the same question.

  2. joesmith
    March 29, 2016 at 5:14 pm

    I was looking for software like Blat, but with SSL support to send an e-mail to gmail account (to receive notifications on my Android phone). Finally I have found a very good Blat alternative:

    Mail Alert

  3. Anonymous
    January 22, 2015 at 12:02 am

    We've used BLAT in our company's EDI applications for YEARS. We rely on it to notify us when there are errors in any of our automated processes. Great tool!

  4. Anonymous
    January 22, 2015 at 12:01 am

    We've used BLAT in our company's EDI applications for YEARS. We rely on it to notify us when there are errors in any of our automated processes. Great tool!

  5. Tim Bare
    June 21, 2012 at 3:05 pm

    For what it's worth, I also wrote an app for this - SwithMail - i find it quite a bit easier to use than blat (which is why i wrote it, actually...) It's got a nice gui for getting your strings together, has XML support for different templates (that modifiable parameters in the body that you can specify from the CLI, etc...

    has many options Blat doesn't, too, including SSL support. you can check it out @ - and any suggestions are welcome on my forum:

    Great tutorial for Blat, by the way. :)

    • Ryan Dube
      June 21, 2012 at 11:31 pm

      Thanks Tim! I've always felt it would be really nice if there was some sort of GUI to simplify the process. Thanks for posting your app, I'll have to check it out.

  6. dylan
    April 23, 2012 at 7:06 am

    Isn't it a bit confusing? You know how about those that doesn't have enough knowledge in command prompt?

  7. Tim
    January 18, 2012 at 4:02 pm

    You can even run Blat without the install by putting all the options you would put in install on your command line.

    If part of your command line needs spaces, you can enclose that part (ie subject) in quotes.

    Also, in your scripting example, if you put the "strFailedList" string in quotes and separated the individual sites with | instead of -, it would be a list with one site per line.

    Finally, support can be found in the Blat Yahoo Group.

    • Ryan Dube
      January 19, 2012 at 1:09 am

      Awesome tips - thank you Tim!