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:
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) #
Hey thats a nice tutorial, but i faild at the first two steps. i made this .bat file with the code and i got this:(http://www.mediafire.com/view/?91q5ijyz54e8qdc).
And when i look in the registry, i cant even find the “Public Domain” Folder(http://www.mediafire.com/view/?tyrffdtq9awwado)
Can you please help me? I want to use Blat wit FPC-Lazarus on Windows 7 64-Bit
Thanks
Finn
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.
Thanks for the helpful tutorial. That gave me a good idea, how I can use blat.
Thanks for the tutorial.
Easy examples and easy to understand
I lacks the profile management with Blat (it does not work for me)