Skip to main content
Participant
March 31, 2010
Question

Cfpop for gmail - Help Please

  • March 31, 2010
  • 2 replies
  • 4418 views

Hello, Please help with this error :

Error Message

Type: Application

Message: An exception occurred when  setting up mail server parameters.

Detail: This exception was caused by:  javax.mail.MessagingException: Connect failed;   nested exception is:      java.net.ConnectException: Connection timed out: connect.

Here is the Code :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read gmail</title>
<style type="text/css">
body {font-family: Verdana,sans-serif}
.error {color: #f00;}
</style>
</head>
<body>
<cfoutput>
<!--- Directory for attachment files --->
<cfset attachmentFolder = ExpandPath("attachments") />

<!--- Array for attachment name(s) --->
<cfset attachmentNameArray = ArrayNew(1) />

<!--- Array for attachment file(s) --->
<cfset attachmentFileArray = ArrayNew(1) />

<h1>Gmail</h1>

<form action="gmail.cfm" method="post">
   <p><label for="popserver">Mail server:</label><br />
   <input id="popserver" type="Text" name="popserver" value="pop.gmail.com" /></p>
   <p><label for="username">Username:</label><br />
   <input id="username" type="Text" name="username" />
   <p><label for="pwd">Password:</label><br />
   <input type="password" name="pwd" /></p>
   <input type="Submit" name="get email" value="Get E-mail" />
</form>

<cfif IsDefined("form.popserver")>

   <!--- make sure server, username are not empty --->
   <cfif form.popserver is not "" and form.username is not "">
  
   <!--- Turn on SSL --->
     <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) />
   
       <cflock name="cfpop-#form.username#" type="exclusive" timeout="50">

           <cftry>
          
              <cfpop server="#form.popserver#" username="#form.username#" password="#form.pwd#"
          action="getAll" name="getEmail" attachmentpath="#attachmentFolder#" generateUniqueFilenames="true">

           <cfcatch type="any">
           <h2 class="error">Error Message</h2>
            <p><strong>Type:</strong> #CFCATCH.Type#</p>
            <p><strong>Message:</strong> #CFCATCH.Message#</p>
            <p><strong>Detail:</strong> #CFCATCH.Detail#</p>
            <cfabort>
        </cfcatch>
       
        </cftry>
         
       </cflock>
        
<h2>Messages</h2>
      <p><strong>Number of Records:</strong> #getEmail.recordCount#</p>
      <p><strong>FYI - TempDirectory:</strong> #GetTempDirectory()#</p>

      <ul>
         <cfloop from="#getEmail.recordCount#" to="1" step="-1" index="i">
           
                 <li><strong>Row: #i#</strong><br />
                     <em>MessageNumber:</em> #getEmail.messagenumber#<br />
                     <em>UID:</em> #getEmail.UID#<br />
                     <em>From:</em> #getEmail.From#<br />
             <em>Subject:</em> #getEmail.Subject#<br />
                     <em>Message:</em> #getEmail.body#<br />
                
                     <cfif Len(getEmail.attachments)>
                        <cfset attachmentNameArray = ListtoArray(getEmail.attachments, chr(9)) />
                        <cfset attachmentFileArray = ListtoArray(getEmail.attachmentfiles, chr(9)) />
                   
                            <em>Attachments:</em><br />
                            <cfloop from="1" to="#ArrayLen(attachmentNameArray)#" index="num">
                                #attachmentNameArray[num]#<br />
                              </cfloop>
                             
                             <em>Attachment Files Server Location:</em><br />
                             <cfloop from="1" to="#ArrayLen(attachmentFileArray)#" index="num">
                              #attachmentFileArray[num]#<br />
                            </cfloop>
                       
                     </cfif>
                    </li>
         
         </cfloop>
      </ul>
     
      <!--- Turn off SSL --->
     <!---  <cfset jProps.setProperty("mail.pop3.socketFactory.class", "javax.net.SocketFactory") /> --->
     
    </cfif>

</cfif>

Thanks in advance,


Sree

</cfoutput>
</body>
</html>

    This topic has been closed for replies.

    2 replies

    Fernis
    Inspiring
    March 31, 2010

    You're just missing the port attribute in your CFPOP tag. Define it there too, and it'll work.

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

    <cfpop
       server="pop.gmail.com"
       action="getHeaderOnly"
       name="popMessages" port="995" maxrows="10"
       username="afernelius@gmail.com"
       password="topsecret">


    Connection Test OK

    (that account/pw really doesn't work, don't bother ;-)

    --

    -Fernis - fernis.net - ColdFusion Developer For Hire

    Ask_OKAuthor
    Participant
    March 31, 2010

    Thank you guys for your quick responses.

    I defined port over there too. but no luck. would you succeeed..........

    regards,

    Sree

    Fernis
    Inspiring
    March 31, 2010

    It really worked for me. I tested it before posting.

    Can you access the gmail POP with a mail client? Do you have IMAP/POP specifically enabled in your Gmail for that account? (use the web interface / settings)

    (I do have to point out that my version is ColdFusion 9 - I can't say if there would be differences with CF7/8, probably the shouldn't)

    And hey, try increasing the connection timeout radically.

    -Fernis

    Owainnorth
    Inspiring
    March 31, 2010

    My that's an impressive amount of code to write before you've even gotten a connection

    As far as I can see, you're trying to bodge an SSL connection out of CFPOP, no? Not something I've ever tried but then so's swinging and people rave about that.

    I'd say first up start with a clean page - no HTML, no nothing and just concentrate on getting the connection working. Does it work over normal non-ssl port 110 traffic? Do you have any kind of network monitoring software like WireShark you could use to see what port the traffic is going out on?

    The error message is obviously fairly self-explanatory - it can't connect. Unfortunately I don't know enough about Java to be able to help there, but I would start by stripping everything back to basics. If CF is actually sending the request on port 995 then it might be a problem with something else, perhaps the protocol. If it's using port 110, then it's something with your java settings.

    Not a massive help I know, but it's something

    O.