sábado, 13 de outubro de 2007

Connecting to Gmail using CFPOP

This is a brief translation of the original post regarding the same subject in brazilian portuguese.

Researching the web (and also after hours trying some native solution) I could realize a lot of people had already tried to use to retrieve data from their Gmail accounts. It makes a lot of sense, but unfortunately doesn’t implements SSL on its algorithm. It makes impossible to reach the desired result.

After some hours looking for solutions for this, discarding the option to use CFX_POP (paid solution), we and my colleague Jefferson Petillo decided to research some alternative. I choose to go into Java direction and after some time researching I found this post (http://unk1911.blogspot.com/2005/12/gmail-via-pop3-in-java.html).

Based on it, I wrote the following simple lines of code to successfully retrieve messages from my Gmail account using :



IMPORTANT: Comparing the original code I had as the base to produce mine, you can realize I omitted the definition ("mail.pop3.socketFactory.fallback", "false") that is equivalent to define it as TRUE. This FLAG makes JVM recovers or not the original “SocketFactory” class used on Pop3 Socket connections that is “javax.net.SocketFactory". If FALSE is defined to “fallback” flag, JVM, from here on, will always use SSL in future Pop3 Socket connections until "mail.pop3.socketFactory.class" is defined back to “javax.net.SocketFactory” instead of "javax.net.ssl.SSLSocketFactory" we are using to implement SSL. For a ColdFusion shared environment it would result on an undesired situation where every Pop3 Socket connection made from any application running that server instance, to use SSL when was implemented. This would produce a connection error when POP server doesn’t requires SSL.

Regarding this, the better way to implement this solution would be:



Where “someFlag” will be some variable indicating SSL is required for next request. It could be, for example, a checkbox form field that will exists in FORM scope if it was checked. In this case “someFlag” can be replaced simply by:



GREAT QUESTION: Why isn’t it already implemented as a simple parameter, just like SSL=”true/false” by Adobe / Macromedia / Allaire?


Special thanks:
The author of the original Java solution posted here http://unk1911.blogspot.com/2005/12/gmail-via-pop3-in-java.html and Jefferson Petilo for his help, curiosity, effort and sleepiness.

3 comentários:

Cedric Villat disse...

Thanks! I've been looking for something like this. Will have to give it a whirl.

Anônimo disse...

Thanks for the great tip. I'm running into an issue tho. 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 its because the ssl certificates aren't explicitly accepted, hence that security error. Is there anything you can do to over come that ?

Vicente Junior disse...

Hi "anonimous", can you provide the code you're using to experience this? So I can do some labs and try to discover the solution and post it here. If you prefer, you can send me an email. Mine is macieljr@gmail.com

Also, if the server you're trying to connect to is private, can you provide me an account for testing purposes?

Thanks for the feedback!