Wednesday, January 17, 2007

Command line emailing via Gmail's POP3 interface

Gmail has a POP3 interface which lets you use your own email client. This opens up a lot of possibilities. One thing I use a lot is the command line email tool Blat, but it can't deal with Gmail's SSL requirement. That's where Stunnel comes in. It will wrap the TCP connections from Blat inside SSL.

After installing Stunnel, edit the config file stunnel.conf. I made the following changes:

; Use it for client mode
client = yes

accept =
connect =

Save the changes and start Stunnel. This makes it look like you have an SMTP server running on your local machine at port 465. Next, just point blat to this local smtp server.

blat -install 1 465 - your_user_name your_password

That's it. You can now send email from scripts and batch files using Gmail's SMTP server.

You can also point other mail apps to this port if they don't support SSL for sending mail.


  1. Thanks for those instructions. I didn't know what I was letting myself in for when I went looking for a "simple" way to email myself backups. Now ... last thing is to FULLY automate it. How do I start the stunnel server, run my batch file and end the stunnel server?

  2. Go to the start menu, select stunnel and install it as a service. Then start it. It will start automatically as a service every time you boot windows. You can run your batch file through Windows' built in scheduler.

  3. Thanks very much. Appreciate your taking the time to answer.

  4. Hmm, I did just like you have and I get :

    Error: Wait a bit (possible timeout).
    SMTP server error
    Error: Not a socket.
    Error: Not a socket.

    when I run my blat from the command line.
    The exact same blat reconfigured to use a pacbell account works fine and will deliver using plain jane Blat without stunnel. My stunnel conf is exactly like what you setup; any ideas?

  5. bruce, did you start the stunnel service? check in the services panel to see if it says it's running.