I was looking for a way to create quick reminders for myself. After trying a few different programs, I looked to the command line to see what I could come up with. It turns out that “command-line email” is perfect for my needs. By combining Blat, Stunnel and Gmail, you can create a great reminder system for taking quick notes.
I’ve been a long time fan of blat, a command line utility that uses SMTP for sending quick messages. The problem is that a SMTP Server isn’t always available to every computer. For awhile, I was loading a separate SMTP Server program on any computer that I needed to use blat on. I have since found a far easier method. Enter Gmail. The geniuses at Google have done it again, allowing the smtp protocol to be used by your Gmail account.
The first step is to download blat and extract the 3 files to your C:\WINDOWS folder. Next.. download Stunnel to your computer. I was attempting to setup Gmail’s SMTP for quite a while before realizing that SSL is required and that’s why I couldn’t connect. This is a good thing though.. as we are now assured the messages we send to Gmail from blat are completely secure. Stunnel provides the tunnel. After downloading and installing, you’ll need to edit your stunnel.conf file with the following settings (yes, just overwrite everything in the file with this):
# GLOBAL OPTIONS
client = yes
output = stunnel-log.txt
debug = 0
taskbar = no# SERVICE-LEVEL OPTIONS
[SMTP Gmail]
accept = 127.0.0.1:1099
connect = smtp.gmail.com:465[POP3 Gmail]
accept = 127.0.0.1:1109
connect = pop.gmail.com:995

Now, start the service and then ‘Run Stunnel’ (both options from Program Files). Your secure tunnel is established. (We’re not actually using POP3 settings since we’re just interested in creating outgoing (SMTP) mail, but if you setup an email client (Oulook, Thunderbird, etc..), you could enable POP3 in your gmail settings and take advantage of this also. )
Finally, run the blat command line options to install SMTP to your computer and run the batch file we create for our command line reminders. Pull up a command prompt and this to install: blat -install smtp.gmail.com youremail@gmail.com -u gmailusername -pw gmailpassword – - gmailsmtp
This creates a registry entry with your smtp profile including a gmail encrypted username and password. Next up.. create the batch file that we’ll call when we type in the command line. It’s just as simple as this: c:\windows\blat.exe -p gmailsmtp -to youremail@gmail.com -subject Note: -body %1 -server 127.0.0.1:1099
Name your file note.bat and drop it in C:\WINDOWS as well. Now, pull up a command prompt and type: note “here’s some text to send”
Check your email.. and there’s your new note.
Keep in mind that you can send your email to anyone, as you’re just using the SMTP protocol from a designated gmail account. You also have a huge amount of other options that you could include your batch file so check out the blat syntax. You’re only limited by what blat can’t do and blat can do a lot!

Hi. I’m trying to make this work but I’m confused on how to get Stunnel going. I downloaded it and installed. Is it just running now?
Marcy.. You’re making it too hard. Look in Program Files after you install Stunnel. It’s all right there.. Install the Service, Run it and then just click on ‘Run Stunnel’. You used to have to manually configure everything with Stunnel. Now it’s pretty seamless. They’ve done a great job improving it.
Jeff,
Thank you very much for your excellent article. I followed it carefully and it worked first time.
One odd thing I noticed is that in the “blat -install” example the gmailpassword – -
part has what look like two hypens but they are two different characters.
They do work… blat likes them.
Regards,
Brian
Thanks, Brian.
I’m using the “- -” characters as defaults. If you check out the blat install syntax (http://www.blat.net/examples/install&profile.html), and look at the last example on that page, you’ll see those characters mean we’re using the default number of tries to send and port number.
Granted.. I later specified a port. You wouldn’t have to do that. I just realized I had to on the server I was on and that’s why it’s in my example.
Glad it worked for you!
Jeff,
Sorry guess I wasn’t as clear as I could have been.
I was just pointing out the odd occurrence that in your actual example what appear to be two identical hyphen characters are actually two different characters. The first is hex 96, the second hex 2D. 2D is a hyphen.
Depending on program you can actually see a difference between them.
In Word for example.
And if you copy&paste run your example you will see that part of the
output is
retry û time(s)
instead of
retry 1 time(s)
Regards,
Brian
Awesome Jeff, thanks this has helped me a great deal today!
Just a note, is there a typo in your article where you install the blat server? I don’t see the -p for the profile name for blat, only two hyphens at the end of that command/instruction :
-pw gmailpassword – – gmailsmtp
just wondering.
Thanks
Anthony
10/10
worked without a hitch – your explanations reflects serious simplifying intelligence. i use mine to send to my phone’s email number (xxxxxxxxxx@vtext.com using command line.. e.g. from mIRC (a chat program).. this way other people can text me without knowing my phone number, or maybe i’ll set up utorrent or the like to tell me important computer events. gotta stay excessively attuned to my computer, yknow! =|
thanks, tho =D
+)
Jeff,
I was looking for some help to send email using gmail and blat and found excellent help from this site. Tons of thanks for putting this together.
Just wanted to thank you for an excellent tutorial. Very helpful and informative for first time users. Thank you.
Hi
I tried an example and this is the result :
Error: Connection to server was dropped.
SMTP server error
Error: Not a socket.
Error: Not a socket.
Can you help me please ?
The install parameters don’t match to the Blat 2.6.2 help:
@gt57 You must not be familiar with the command line. You can specify your variables at any place… doing it as I have or using the manual and doing it exactly as it states, as you or others may need to do.
Notice those replies above yours? It works for them as it has for me.. dozens of times. I copied and pasted what I use so it does work. You just need to use a bit of intelligence in implementing it.
Thanks man, this has really gone a long way.
I tried all kinds of other instructions. but your were simple and worked the first time.
Thank you!!!!
Nice clear instructions, worked the first time, Thanks!
Absolutely Great!
Thank you!
Thank you very much – quite helpful!
Thanks! Was trying to get blat, stunnel & gmail working to no avail, your clear instructions and I had it working in less than 10 minutes, great info.
Thanks, guys. Glad the information is helping others and it’s working for you!
supernicelyworks!
thanks a lot!
But I still do not get why we need stullel. Why can’t we use only Blat and Gmail?
I explain that in the 3rd paragraph above: “I was attempting to setup Gmail’s SMTP for quite a while before realizing that SSL is required and that’s why I couldn’t connect.”
Even if it wasn’t required, I would use it. Tt’s an SSL encryption wrapper so you can rest assured that your messages (along with your authentication information) will never be intercepted.
Thanks a lot!! Very very helpful!
Though i got all this done, i still have a little trouble. It’s when I send email, I found out that the “send time” isn’t correct, it’s less 1 hour than the actual sending time! ex: I use blat to send email at 12:00, i get the mail at around 12:00, but the send time is around 11:00. I checked my system time and time zone, they were all correct, but i still got the issue.
I could not find the time setting option in both blat and stunnel.
Could you help me for this or tell me where might be wrong?
Not sure Marvin, as I’ve never had this issue. I see some others on the TechBoard have had the same problem though. You might rehash the issue and ask them. Check this link: http://tech.groups.yahoo.com/group/blat/message/11346
Best of luck.
Thank you!
You could use sendEmail (http://caspian.dotconf.net/menu/Software/SendEmail/) instead of blat… has TLS built in, so no need for stunnel. sendEmail + Gmail = done.
Nice mention, Scott. I’m not familiar with sendEmail but it looks like a nice alternative solution.
Just wanted to say thanks for this article, within 5 mins I had it running.
Came across blat today as needed to email backup logs from my Veritas server, then thought abou tusing it at home also.
Stunnel is cool.
Thanks Paul. I appreciate the words. Glad it helped you out!
The message Error: Not a socket was caused due to another service, in my case c:\windows\system32\Lserver.exe (Terminal server Licensing) using the same port 1099. Not tested yet, but changing the port to another unused in the config file should solve the problem.
You can use the program “active ports” available in Internet to see what programis using that port.
I have a pc with windows 7 – 64 bit and I am very eager to use Blat also with Google.
I have followed the instructions to install Stunnel literally:
“Now, start the service and then ‘Run Stunnel’ (both options from Program Files)”.
Apparently before starting the service I must install it. Correct?
After installing the service, starting it is no problem and it can be found in services.msc
The next step, ‘Run Stunnel’, is where it goes wrong and I have no clue what to do.
This is the message I get:
Stunnel 4.48 on Win32 (invalid stunnel.conf) [This is the message header]
No limit detected for the number of clients
make_sockets: s_socket#1: FD=464 allocated (blocking mode)
make_sockets: s_socket#2: FD=468 allocated (blocking mode)
make_sockets: s_accept: FD=472 allocated (non-blocking mode)
stunnel 4.48 on x86-pc-mingw32-gnu platform
Compiled/running with OpenSSL 0.9.8r-fips 8 Feb 2011
Threading:WIN32 SSL:ENGINE,FIPS Auth:none Sockets:SELECT,IPv6
Reading configuration from file stunnel.conf
FIPS_mode_set: 2D06906E: error:2D06906E:FIPS routines:FIPS_CHECK_INCORE_FINGERPRINT:fingerprint does not match
Server is down
End of message
Any help would be highly appreciated.
Many thanks indeed
If I can get this to work it is probably my best X-mas present. Thanks a lot Jeff
Hi Pieter. I haven’t installed on W7 or 64-bit but the problem seems to definitely be that Stunnel is using 32-bit mode (as stated in your message header) and you’re installing on a 64-bit system. I don’t see separate binaries for these downloads, so I suspect that that there’s some editing needed in stunnel.conf.
Unfortunately, it’s been almost 2 years since I wrote this post or messed with Stunnel and I’ve only done it with XP so I’m not much help on the newer issues. It served my purpose well back when I wrote this post but I no longer need or use Stunnel.
Best of luck to you.
i spent quite literally 2 weeks trying to get stunnel to work so my canon copier would talk to gmail.
the problem was that i could enable SSL on the canon copier but i could not change the port. so it wouldnt talk to gmail.
here is my stunnel.conf for any one who is having as much trouble as i did getting stunnel and gmail to work. the gmail account has pop/imap enabled in the mail settings in gmail. 192.168.150.2 is my internal windows server running stunnel. i could not get 127.0.0.1 to work. i just put my stunnel servers ip in the copier as the mail server 192.168.150.2. also i think i had to turn off smtp auth on the copier for it to work. your mileage may vary…
just copy paste this into your stunnel.conf for gmail.
cert = stunnel.pem
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
client = yes
[pop3s]
accept = 110
connect = pop.gmail.com:995
[imaps]
accept = 143
connect = imap.gmail.com:993
[ssmtp]
accept = 25
connect = smtp.gmail.com:465
I still cant get this to work, please can you send me a link to that stunnel file because there are many and i dont know which file to download
thanks
@ECHO OFF
title Menuchoice
:home
color 17
ECHO Select a task:
ECHO ==============
ECHO.
ECHO 1) Install BLAT
ECHO 2) Install SMPT
ECHO q) Quit
ECHO.
set /p web=Type option:
if “%web%”==”1″ goto FIRST
if “%web%”==”2″ goto SECOND
if “%web%”==”q” Exit
cls
goto home
:FIRST
blat -install smtp.gmail.com JOHN.DOE@gmail.com -u JOHN.DOE -pw JOHNY1991 – – gmailsmtp
pause
cls
goto home
:SECOND
c:\windows\blat.exe -p gmailsmtp -to JOHN.DOE@gmail.com -subject “DEAR SANTA” -body “HOW ARE YOU” -server 127.0.0.1:1099
pause
cls
goto home
#whats the problem here, at the last i get errors; couldnt connect or when i change the
#servers ip it seems to attempt for connecting but after 10 sec, max it says the servers
#rejected the connection or something like that.
#i installed [stunnel-4.50-installer.exe](926KB) to the Program Files under C: and edited #stunnel.conf, moved the three (BLAT) files to the WIN directory and this batch i always #ran from there[which i think isnt the problem of the paths]