5 Replies Latest reply: Mar 30, 2013 1:46 AM by Bill Shannon-Oracle RSS

    Cannot connect to mail server using Java 7

    999914
      I have an application using JavaMail that has been working for years.

      When I upgrade from Java 6 to Java 7 it fails to connect to the mail server.

      I am now trying to use the msgsendsample example application and the same thing happens i.e. works with Java 6 but not Java 7!

      I am using eclipse juno with java 6 JDK.

      Here is the debug output...

      To: support@cleverpsych.com.au
      Subject: testing
      DEBUG: setDebug: JavaMail version 1.4.7
      DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
      DEBUG SMTP: useEhlo true, useAuth false
      DEBUG SMTP: trying to connect to host "mail.bigpond.com", port 25, isSSL false
      javax.mail.MessagingException: Could not connect to SMTP host: mail.bigpond.com, port: 25;
      nested exception is:
           java.net.SocketException: Permission denied: connect
           at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
           at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
           at javax.mail.Service.connect(Service.java:295)
           at javax.mail.Service.connect(Service.java:176)
           at javax.mail.Service.connect(Service.java:125)
           at javax.mail.Transport.send0(Transport.java:194)
           at javax.mail.Transport.send(Transport.java:124)
           at test.msgsendsample.main(msgsendsample.java:192)
      Caused by: java.net.SocketException: Permission denied: connect
           at java.net.DualStackPlainSocketImpl.connect0(Native Method)
           at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
           at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
           at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
           at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
           at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
           at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
           at java.net.Socket.connect(Socket.java:579)
           at java.net.Socket.connect(Socket.java:528)
           at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321)
           at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
           at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
           ... 7 more


      I suspect that the security is tighter in Java 7 and I may need a certificate to access the mail server.


      Any suggestions / help would be appreciated.

      Lloyd
        • 1. Re: Cannot connect to mail server using Java 7
          Bill Shannon-Oracle
          It does look like a security problem, but if you're running a standalone application (not an applet),
          I don't think it should be any different between 6 and 7. Are you running msgsendsample outside
          of Eclipse, e.g., by using the "java" command? Perhaps Eclipse is behaving differently between
          Java 6 and 7?

          I don't think it's a certificate problem. It's failing before you even connect, and you're connecting
          on the plain text SMTP port (25), so certificates should not be involved. Plus, generally, the client
          doesn't need a certificate to connect to the server, it just needs to validate the server's certificate.
          • 2. Re: Cannot connect to mail server using Java 7
            999914
            Thanks for the quick reply.

            I am running the example within eclipse, but my application which is also failing is of course stand-alone.

            I do have some old JARs on my classpath, but I tried removing them and it didnt make any difference. Perhaps I didnt remove the correct ones.

            C:\CleverPsych\jars>dir
            Volume in drive C is OS
            Volume Serial Number is 9A08-5929

            Directory of C:\CleverPsych\jars

            29/03/2013 11:49 AM <DIR> .
            29/03/2013 11:49 AM <DIR> ..
            18/10/2012 07:11 PM 566,592 collections-generic-4.01.jar
            18/10/2012 07:11 PM 620,787 colt.jar
            18/10/2012 07:11 PM 615,778 commons-collections-3.2.1.jar
            18/10/2012 07:11 PM 242,015 concurrent.jar
            18/10/2012 07:11 PM 329,156 jcommon-1.0.12.jar
            18/10/2012 07:11 PM 1,342,226 jfreechart-1.0.9.jar
            18/10/2012 07:11 PM 983,617 jung-1.7.6.jar
            18/10/2012 07:11 PM 372,645 log4j-1.2.8.jar
            06/03/2013 04:16 PM 521,000 mail.jar
            29/03/2013 11:49 AM 898,760 psycho.jar
            10 File(s) 6,492,576 bytes

            Any other suggestions?

            Lloyd
            • 3. Re: Cannot connect to mail server using Java 7
              Bill Shannon-Oracle
              Let me make sure I understand...

              If you run the standalone msgsendsample application using the "java" command from Java 6, it works.
              But if you run that application using the "java" command from Java 7, it fails with the "permission denied"
              exception?

              Exactly what java command line and arguments are you using?

              Is it possible that you have a firewall or anti-virus product that has been configured to allow the Java 6
              "java" command to make connections, but hasn't been configured to allow the Java 7 "java" command
              to make connections?
              • 4. Re: Cannot connect to mail server using Java 7
                999914
                The problem is Norton antivirus.

                If I turn off scanning of outgoing Email messages Javamail then connects and sends using Java 7.

                Thanks for your help.
                • 5. Re: Cannot connect to mail server using Java 7
                  Bill Shannon-Oracle
                  Ah ha!!!

                  I'm surprised it didn't at least notify you in some way that it was blocking this.