Using Blat, Stunnel and Gmail Together
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 Brian, 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