No SSL With ColdFusion's CFPOP?
I was very surprised to find out that ColdFusion's CFPOP tag does not support POP3 SSL. ColdFusion is over 10 years old now...you've got to add that in, Adobe!
Anyway, I did some digging around, and thanks to a comment on another blog by Darin Tyler, I found an easy fix. You can use some simple Java commands to "force" cfpop to use SSL. In my testing, I used Gmail, and the code is below:
<cfset javaSystemProps = javaSystem.getProperties() />
<cfset javaSystemProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<cfpop
server="pop.gmail.com"
action="getAll"
name="popMessages"
port="995"
username="myemailaddress@gmail.com"
password="i'mnotgoingtotellyou">
Jake Munson
38 Yrs old
The Java call is the way to go, and I wanted to share one additional technique I've used with it: you'll want to turn SSL off if the user turns it off to access another POP account, or if the same application serves multiple users who don't all use SSL. So after you turn SSL on with the line:
<cfset javaSystemProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
You can turn it off with:
<cfset javaSystemProps.setProperty("mail.pop3.socketFactory.class", "javax.net.SocketFactory") />
I'm actually trying this out but coming up with a few issues. Just tried writing a sample block that will connect to gmail but the server is returning
An exception occurred when setting up mail server parameters.
This exception was caused by: javax.mail.MessagingException: Connect failed; nested exception is: javax.net.ssl.SSLException: untrusted server cert chain.
I'm guessing since the SSL cert was not explicitly accepted, the security sandbox blocks this. Any workaround for this ?
The codes are:
<CFTRY>
<CFSET javaSystem = createObject("java", "java.lang.System") />
<CFSET javaSystemProps = javaSystem.getProperties() />
<CFSET javaSystemProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<CFPOP name = "rsCheckNew" action = "getHeaderOnly"
server = "pop.gmail.com" port = "995" timeout = "10"
username = "myusername" password = "mypassword">
<CFCATCH type="any">
<CFSET msg = "Error Checking POP3 Account.">
</CFCATCH>
</CFTRY>
I can't see a difference between your code and the code I put in my blog entry. Not sure what's going on, unless Google changed things on their end. I wrote this a few months ago and haven't tried this code since, so maybe Google doesn't allow this anymore?
Thanks
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
My guess is this is has to do with the missing cert you mentioned a few comments above. Did you write that 2nd blog post on how to connect to MS Exchange?
Thanks,
Eric
I don't remember if I ever wrote that second post, but I definitely needed the Exchange guys to work with me on the SSL issue. It's been so long ago now that I can't remember everything we did...but it does work for us. I use the above code, and with the SSL certs in their proper places I'm able to use SSL POP to pull messages from an Exchange mailbox.