Using Blat, Stunnel and Gmail Together

Create an efficient reminder system for yourself using "command-line email".

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):


client = yes
output = stunnel-log.txt
debug = 0
taskbar = no


[SMTP Gmail]
accept =
connect =

[POP3 Gmail]
accept =
connect =

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 -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 -subject Note: -body %1 -server

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!


  1. 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?

  2. 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.

  3. 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.


  4. Thanks, Brian.
    I’m using the “- -” characters as defaults. If you check out the blat install syntax (, 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!

  5. 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)


  6. 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.

  7. 10/10
    worked without a hitch – your explanations reflects serious simplifying intelligence. i use mine to send to my phone’s email number ( 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

  8. 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.

  9. Just wanted to thank you for an excellent tutorial. Very helpful and informative for first time users. Thank you.

  10. 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 ?

  11. The install parameters don’t match to the Blat 2.6.2 help:

  12. @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.

  13. Thanks man, this has really gone a long way.

  14. I tried all kinds of other instructions. but your were simple and worked the first time.

    Thank you!!!!

  15. Nice clear instructions, worked the first time, Thanks!

  16. Thank you very much – quite helpful!

  17. 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.

  18. Thanks, guys. Glad the information is helping others and it’s working for you!

  19. supernicelyworks!
    thanks a lot!
    But I still do not get why we need stullel. Why can’t we use only Blat and Gmail?

  20. 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.

  21. 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?

  22. Nice mention, Scott. I’m not familiar with sendEmail but it looks like a nice alternative solution.

  23. 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.

  24. Thanks Paul. I appreciate the words. Glad it helped you out!

  25. 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.

  26. 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

  27. 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.

  28. 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. is my internal windows server running stunnel. i could not get to work. i just put my stunnel servers ip in the copier as the mail server 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

    accept = 110
    connect =

    accept = 143
    connect =

    accept = 25
    connect =

  29. 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

  30. @ECHO OFF
    title Menuchoice
    color 17
    ECHO Select a task:
    ECHO ==============
    ECHO 1) Install BLAT
    ECHO 2) Install SMPT
    ECHO q) Quit
    set /p web=Type option:
    if “%web%”==”1” goto FIRST
    if “%web%”==”2” goto SECOND
    if “%web%”==”q” Exit
    goto home

    blat -install -u JOHN.DOE -pw JOHNY1991 – – gmailsmtp
    goto home

    c:\windows\blat.exe -p gmailsmtp -to -subject “DEAR SANTA” -body “HOW ARE YOU” -server
    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]

  31. Thanks, Jeff

    I have been using an SMTP relay for years to send email via Google and this is so much simpler. It worked perfectly the first time. And all open source!

  32. Santi..

    Glad it worked well for you! Thanks for letting me know!
    Have a great one,


  33. Hey jeff … Good trick…!
    i can send emails in cross domain also….!

  34. I tried the directions today exactly as specified, and even see the stunnel connection in the logs going out to the Google Gmail server at port 465, but when I run blat (exactly as specified) however I get the odd error below. I have confirmed by double checking that I have all set up properly:

    Warning *** The SMTP server did not accept Auth PLAIN value.
    Warning *** The SMTP server did not accept Auth LOGIN PASSWD value.

    Has anybody else seen this using stunnel and the above recipe?

  35. Okay, solved my problem above and it was very very odd. Using the latest version of blat.exe the password being passed in with -pw was not working. We noticed that we had case-sensitive password, so we changed it to all lowercase just to see if this had any effect and it did. Why would this be case sensitive I have no clue (something in the command line parsing from blat.exe version 3.0.2?).


  36. update to install:

    1) Install stunnel and blat as above
    2) Start->programs->stunnel->Service Install
    3) Start->programs->stunnel->Service start
    4) Start->programs->stunnel->Run stunnel
    5) in the stunnel window (a grey window should appear after the previous command): Configuration -> Edit stunnel.conf
    6) paste Galen’s config:


    cert = stunnel.pem
    socket = l:TCP_NODELAY=1
    socket = r:TCP_NODELAY=1
    client = yes

    accept = 110
    connect =

    accept = 143
    connect =

    accept = 25
    connect =

    7) Configuration -> reload configuration
    8) Start->programs->stunnel->service stop
    9) Start->programs->stunnel->service start
    10) Start-> search for ‘cmd’ (command prompt)
    11) Run as administrator (this step might not be necessarily)
    12) (as per blat docs, -install is not necessary) navigate to directory which has blat.exe and run this test command:

    blat – -u -pw -to -subject “subject” -body “body” -server

  37. the last command was edited by the blogging software

    blat – -u (gmail username without ‘’) -pw (gmail password) -to (to: email) -subject “subject” -body “body” -server

  38. This couldn’t have been any simpler. Thank you!

  39. Hi Jeff ,

    Kindly see the error and help me out , appreciate your help

    C:UsersAnkur>c:windowsblat.exe -p gmailsmtp -to ************** -su
    bject Note: -body “test” -server
    Blat v3.0.7 (build : Jul 20 2012 01:24:19)
    32-bit Windows, Full, Unicode

    Error: Server refused connection.


  40. Google changed their server to did not work for me. Spent 8 hours to figure this out as I tried everything first.

  41. Outstanding write up and great info, not that you haven’t heard that a a thousand times and you should. Really outstanding information.

    The question I have have you, or anyone, attempted to do this with multiple GMail accounts? Basically let’s say you have 3 websites on one server and you want each site to use its own email account to post the forms.

    It seems that it would be doable, assigning a name and password to the email address used and then using that email address. Just wondering if it has been done before I attempt it.

    Thanks again for the post

  42. Thanks to you I have been using blat, stunnel and gmail for quite a while. The only issue I have is when I want to send out 400 or so emails(one by one) I seem to be limited to sending about 70 at a time. Therefore I have to send out in batches. What is causing this?

  43. That’s your email provider. They limit the amount of emails you can send at once. You’re still using their mail server to accomplish this task so they set the rules and all of them do this to prevent spam. If you want to send out thousands at once, you have to sign up for something like mailchimp.

Submit a comment

CommentLuv badge

reverse phone lookupTattoo DesignsSEO
My New Amazon Script Is Close!
A new php script for sale is coming!
Sign up to get notified