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

 

<cftry>
<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#">

TrackBacks
Get Google Apps (gmail) mail via Coldfusion CFPOP
This guy is really a smart fellow good stuff it works perfectly for me.
Tracked by William Whealtey | Tracked on 2/14/08 9:02 AM

Trackback URL for this entry:
http://www.cfedge.com/trackback.cfm?6E37DF59-15CA-1072-1E4CCEC24E72BDAD

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Darin Tyler's Gravatar You can get gmail to work with ColdFusion by adding the following lines before the cfpop tag:

<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.)
# Posted By Darin Tyler | 1/18/08 7:29 AM
kaigler's Gravatar Thanks Darin, great addition. Worked like a champ.
# Posted By kaigler | 2/4/08 9:57 AM
Sean Harrison's Gravatar Stunnel + CFPOP = works great! Thanks!
# Posted By Sean Harrison | 4/30/08 12:44 PM
# Posted By Erik Madsen | 9/22/08 2:56 PM
Jennifer Suarez's Gravatar I realize this was posted years ago, but it's still relevant and it worked well for me, especially when combined with the comments of others.

Just wanted to say THANKS!
# Posted By Jennifer Suarez | 3/18/09 5:03 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.7.