Menu Close

How to send emails using blat

Blat is a handy Win32 console utility that enables you to send emails via the command line, on Windows machines. This is especially useful within batch scripts.

Given below are some how-tos on basic uses of blat. Refer the blat syntax page for more options with blat. The commands below have been tested on Windows Server 2003 with blat v2.6.2, unless otherwise stated.

HOW-TO 1: Configure the SMTP Relay for blat

The blat utility can perform functions of both an MUA and an MTA. Before using blat, you may configure certain options in the Windows Registry to avoid typing them repeatedly whenever sending emails (using overrides on the command line). An example configuration is given below:

blat -installSMTP mymailer.smtp.xyz.com sender@xyz.com 5 25
#
# where:
# mymailer.smtp.xyz.com => SMTP Relay host's domain name
# sender@xyz.com => sender's email address
# 5 => Number of retries (default=1)
# 25 => SMTP Server port (default=25)
#

After executing the command in the above example, your Windows Registry should have entries for blat as shown in the image below:

Blat_RegistryInstall

HOW-TO 2: Send email with empty body

blat -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -body " "
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# -body => blank body (blankspace within double-quotes)
#

NOTE: To send email with a body, just type the message within double-quotes in the -body option.

HOW-TO 3: Send email with body from a file

blat body.txt -s "Test mail" -i "Cybergavin Tester" -to test@abc.com
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# body.txt => file containing message body
#

HOW-TO 4: Send attachment(s)

blat -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -body "Please see attached"
 -attach test.txt
#
# where:
# -s => Subject
# -i => Sender's Name
# -to => Recipient's Email Address
# -body => Message Body
# -attach => Binary File to be attached
#

HOW-TO 5: Send HTML email

blat body.html -s "Test mail" -i "Cybergavin Tester" -to test@abc.com -html
#
# where:
# -s => Subject (NOTE: If you don't provide a subject, then default subject is
#     "Contents of file: stdin.txt"
# -i => Sender's Name (NOTE: Sender's email address already configured in STEP 1)
# -to => Recipient's Email Address
# body.html => file containing message body in HTML format
# -html => Use HTML format (Content-Type : text/html)
#

VN:F [1.9.22_1171]
Rating: +36 (from 40 votes)
Print Friendly, PDF & Email

4 Comments

  1. mrkips

    Finn: Thank you. I just installed the latest version of Blat (v3.07) on my Windows 7 laptop and found Blat’s registry entries at Computer\HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\Public Domain\Blat

    You may also use Ctrl+F in the registry window and search for “blat”.

    The article pertained to Blat v2.6.2 on Windows Server 2003.

  2. Jan

    Thanks for the tutorial.
    Easy examples and easy to understand
    I lacks the profile management with Blat (it does not work for me)

Leave a Reply

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