Using CFPOP to Connect to Gmail Using Stunnel
Finally I had a chance today to work on a project that I had put on the back burner only to find out that cfpop doesn't appear to work with SSL. I wanted to use cfpop to connect to one of my gmail accounts. I started by typing in all the information into cfpop as directed by Google. I put my code into a try / catch with a cfdump of the mail query name. I made sure to pop only 1 message for testing. My cfm page choked. It timed out without a successful connection. At this point I was not worried, I did what every resourceful programmer would do--Read The Docs. I went to my trusty Windows CFM File of the Coldfusion Documentation and start poking around. The documentation didn't have anything so I then went to Google and did a search. The only entries at first were links to a custom tag that cost money to make ssl connections to pop accounts. That wasn't a good solution because I didn't want to have to spend money, after all this wasn't for a client, it was just a little project.
What to do... Wait! I know..
Yesterday I had installed the Mercury Mail Transport Program on my local machine to test some mailer cfm pages I had been working on. I had remembered seeing a feature in the program that would go out and pop outside accounts and put them in a local box on the server. This I thought to be a good idea. I could user Mercury Mail Server to pop Gmail and then I could just pop the local account in my cfm page. Well wouldn't you know it, Mercury Mail Server won't pop ssl boxes either. I then went back to Google and looked to see if there was a way to configure the Mercury Mail to do what I needed it to do. I read a post that talked about using Stunnel to connect to an pop3 ssl account.
You can probably guess what I did next...
I did a search on Stunnel and wound up here. I installed the windows version of Stunnel. I quickly realized I was not going to be able to click a button and have it work right off the get go. I also thought to myself, there isn't any reason why I shouldn't be able to use Stunnel to connect my cfpop cfm page to Gmail. I went back to Google and did a search for "Stunnel Gmail". It lead me to a cool tutorial on SpamPal. The tutorial shows how to configure Stunnel to connect to Gmail and your email client to connect to Stunnel. With some trial and error I was able to get my cfpop cfm page to connect to Gmail using SSL. YES! I did it.
That is where I am right now. It took a lot longer than I would have liked. Now my project will have to wait till another day, but I can be happy that I was able to accomplish something, that it doesn't look like a lot of programmers have been able to do. My cfpop code is below for you to see how it works.
NOTE: I did have to turn off my firewall and turn it back on to get it to prompt me to allow Stunnel to connect to the outside world.
NOTE 2: I did not follow the tutorial exactly when it came to the configuration. I found that I did not have to put the @127.0.0.1:1109 after the username
<cfpop
server = "127.0.0.1"
port = "1109"
username = "youremail@gmail.com"
password = "yourPassword"
action = "getAll"
name = "popMail"
attachmentPath = "#ExpandPath('./attachments')#"
timeout = "60"
maxRows = "1"
startRow = "1"
generateUniqueFilenames = "yes"
>
<cfcatch type="any">
<cfdump var="#cfcatch#">
<cfabort>
</cfcatch>
</cftry>
<cfdump var="#popMail#">
This guy is really a smart fellow good stuff it works perfectly for me.
http://www.cfedge.com/trackback.cfm?6E37DF59-15CA-1072-1E4CCEC24E72BDAD



<cfset javaSystem = createObject("java", "java.lang.System") />
<cfset javaSystemProps = javaSystem.getProperties() />
<cfset javaSystemProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
(Easiest solution I have seen so far.)