Using K9 and Stunnel to Filter Spam from Gmail

By Kristen
Updated July 28, 2007

K9 is my favorite spam filtering software, but it alone won't work with Gmail. I'm praying that one day there will be a version of K9 that will automatically handle SSL, but until then you can install Stunnel and configure it to work with K9. This will allow K9 to access SSL accounts like Gmail. It's a bit complicated, but just follow the steps.

(Note: This tutorial is for Windows XP, but you can probably figure out how to adapt these instructions for your operating system.)

  1. Setup Stunnel.
    1. Download the latest version of Stunnel from the Windows installer page, Windows installer page is a bit confusing, but just look on the list for the most recent version of the stunnel installation program (ending in .exe not .asc). It is usually at the top of the list. For example, as of the writing of this tutorial (Nov. 26, 2006), the current file is stunnel-4.16-installer.exe (Aug. 31, 2006). Save this program to wherever you prefer to save downloaded programs (e.g. My Documents, My Downloads, Desktop, etc.)
    2. Run the Stunnel installation file to install the program on your computer.
    3. Scroll to the bottom of the Windows installer page,, and look for the OpenSSL Libraries section. In that section you will find libss132.dll and libeay32.dll. Save these files in your C:\WINDOWS\system\ directory.
    4. Go to to create a security certificate if you can't or don't know how to do it on your own computer.
      1. Copy all of the code from -----BEGIN RSA PRIVATE KEY----- to -----END CERTIFICATE----- (including the -----BEGIN and CERTIFICATE----- tags)
      2. Paste it into Notepad.
      3. Save the file as stunnel.pem in your C:\Program Files\stunnel directory.
    5. Now you need to configure Stunnel. It's a little scary for anyone who doesn't have much computer experience, but just relax and follow the steps.
      1. Click on the edit shortcut on your Start Menu: Start > All Programs > stunnel > Edit stunnel.conf
      2. Find the line that contains

        ;client = yes

        and delete the semicolon so it is just

        client = yes
      3. Copy the following code and paste it above the line that starts with [imaps]

        accept =
        connect =
        delay = yes
      4. Save the file and close it.
    6. Now, install the Stunnel service. This will allow the program to run as a service in Windows. You can do this from the Start Menu.

      Start > All Programs > stunnel > Service Install

    7. Now you need to run the service. Again, you can do this from your Start Menu.

      Start > All Programs > stunnel > Service Start

  2. Setup K9.
    1. Go to and download the installer for the latest version of K9 program and install the program.
    2. Run the K9 program.
    3. Click on the Advanced tab.
    4. In the POP3 Server box, check the "Enable this account" checkbox.
    5. Configure K9 to check your email account.

      Account Name: your gmail email address
      Server Name/IP:
      Port: 11010
      User: your gmail email address
      Password: your gmail password
    6. Click on the Configuration tab.
      1. Make sure "Listen on" is set to 9999. If not, set it to 9999.
      2. Make sure "Minimize to system tray icon" and "Minimize on startup" are checked. If they aren't, click on the checkbox to check them.
    7. Create a shortcut to the K9 program and put it in your Startup folder, so the program will automatically start when you start Windows.

      Start > All Programs > Start Up

  3. Setup your email client (Outlook, Thunderbird, Eudora, etc.).
    1. Install your email client, if you haven't already.
    2. Setup your email accounts (read your help files to find out how to do this with your particular email program)

      Incoming mail server (POP3):
      Outgoing mail server (SMTP:
      User Name: (replace "" with your gmail email address")
      Password: your gmail password
      Server Port Numbers Incoming server (POP3): 9999 (DOES NOT require SSL / encrypted connection)
      Server Port Numbers Outgoing server (SMTP): 465 (DOES require SSL / encrypted connection)
    3. Now test your account settings by sending an email from gmail account to yourself. (Note: sometimes if you send a message to yourself from your gmail account to your gmail account, it won't download to your email client ... strange, so try sending an email to your gmail account from another email address.)

Thanks to for helping me figure this out.