cfpop and gmail

On May 18, 2008, in ColdFusion, by Anuj Gakhar

I know this has come up with a few times before but its something I want to blog more for myself so I could easily refer to it when required.

By default, cfpop does not support ssl and if you are trying to access your gmail account via cfpop, you wouldnt be able to do so straight away because gmail requires you to access its mail server using ssl. There are a couple solutions around (which can be searched via Google) but the best I found was that you can force socketFactory’s class to use ssl (which is not the default behaviour).

Just add the following few lines of code before your cfpop tag call and that should do it! And dont forget to enable POP access in your gmail account first.


<cfset javaSystem = createObject("java", "java.lang.System") />
<cfset jProps = javaSystem.getProperties() />
<cfset jProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<cfset jProps.setproperty("mail.pop3.port",995) />
<cfset jProps.setProperty("mail.pop3.socketFactory.port", 995) />

Tagged with:  

16 Responses to cfpop and gmail

  1. Steve Glachan says:

    Thanks for this, just what I was looking for :). Works just fine.

  2. Dan says:

    I think there is an error on the second line – isn’t javaSystemjavaSystemProps supposed to be javaSystemProps?

    Dan

  3. Anuj Gakhar says:

    Hi Dan, you are right. For some reason, the colored coder was messing up the variable name. I had to change the variable name to fix it. The post is updated now. Thanks.

  4. Just what I was looking for. Excellent work !

  5. Fabian says:

    I was looking for this!! thanks!! Little question though: do I need to turn it off if I’m going to check another (non-SSL) mail afterwards? How do I do it?

    Thanks again

  6. Anuj Gakhar says:

    @Fabian, good question. Honestly, I havent tried doing that. I would imagine that in the case of a non-SSL mail, you would have to turn it off as it changes the ports that are specific to gmail alone. And since its telling the socketFactory to use the ssl , that will need to change as well. So, I assume this will either have to be turned off or used with the correct values for another mail provider.

    Hope that helps.

  7. Michael says:

    Hey Anuj,

    I’m running into a

    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.

    while trying this. Any idea what I’m lacking ?

  8. Anuj Gakhar says:

    @Michael, sorry for the late reply. Are you still having this problem or did you manage to sort it out?

  9. Fabian says:

    Hi Anuj,

    Just for the rest of us, in response to my question to turn it off, this is how I made it work:

    javaSystem = createObject(“java”, “java.lang.System”);
    javaSystemProps = javaSystem.getProperties();

    //SSL Needed.
    if(SSL){
    javaSystemProps.setProperty(“mail.pop3.socketFactory.class”,”javax.net.ssl.SSLSocketFactory”);
    javaSystemProps.setProperty(“mail.pop3.socketFactory.fallback”,”true”);

    )

    //TURN SSL OFF
    else{
    javaSystemProps.setProperty(“mail.pop3.socketFactory.class”,””);
    }

    That works! 🙂

    Fabian

  10. Michael Borbor says:

    Hi Anuj, I was trying to get to my gmail account, but there’s an additional pickle my internet connection is behind a proxy, maybe you can point to a solution where I can configure cf to route the Pop3 through the Proxy?

    Thanks.

  11. […] for work arounds for this but the simplest and quite elegant solution is the one provided by Anuj Gakhar. This solution uses the underlying Java pop service which does support SSL. […]

  12. Tafazul Gani says:

    Hi guys,

    I keep getting the error javax.mail.internet.MimeMultipart@ade348 for some emails. There are no attachments or content displayed when this happends.

    Anyone knows any work around for this..

    Please assit, really need a work around urgently

  13. Tom says:

    Works like a charm. Thanks!

  14. Sree says:

    Can you help with this Error.

    javax.mail.MessagingException: Connect failed; nested exception is: java.net.ConnectException: Connection timed out: connect.

  15. Arshad says:

    Thanks a lot for this!

  16. Adrian says:

    how to use cfx for mail exchange??

    Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 445 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: