users@glassfish.java.net

Re: Setup of Glassfish Email to use remote server and Port

From: <glassfish_at_javadesktop.org>
Date: Wed, 02 Apr 2008 08:26:30 PST

No problem.

Maybe I can help make the example.

   Here is what I have for attempting to send an email:
   @Resource(name = "<named service>",type=Session.class)
   Session theSession;
   

        boolean success = false;
                
        try
        {
           InitialContext ctx = new InitialContext();
           theSession = (Session )ctx.lookup("java:comp/env/<named service>");
           Transport trans = theSession.getTransport("smtp");
           Message msg = new MimeMessage(theSession);
           msg.setRecipient(Message.RecipientType.TO,new InternetAddress("<Destination>"));
           msg.setSubject("Testing... ");
           msg.setText("This is just a test message!");
           
           trans.connect("<username>","<password>");
           success = true;
        }
        catch(NamingException nex)
        {
           nex.printStackTrace();
        }
        catch(AddressException addr)
        {
           addr.printStackTrace();
        }
        catch(MessagingException mex)
        {
           mex.printStackTrace();
        }
        return(success);

When I attempt to connect to the Exchange server, I get the following failure:

WARNING: javax.mail.MessagingException: Could not connect to SMTP host: nlb-exchange.llan.ll.mit.edu, port: 993;
  nested exception is:
        java.net.SocketException: Unconnected sockets not implemented
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
        at javax.mail.Service.connect(Service.java:288)
        at javax.mail.Service.connect(Service.java:169)
        at javax.mail.Service.connect(Service.java:189)
        at factor3.web.bbase.gui.query.MailBean.sendBorrowRequest(MailBean.java:99)
        at factor3.web.bbase.gui.query.BorrowPanel.initiateBorrowing(BorrowPanel.java:138)
        at factor3.web.bbase.gui.query.BorrowPanel.actionPerformed(BorrowPanel.java:186)
        at thinwire.ui.EventListenerImpl.fireEvent(EventListenerImpl.java:314)
        at thinwire.ui.EventListenerImpl.fireAction(EventListenerImpl.java:246)
        at thinwire.ui.AbstractComponent.fireAction(AbstractComponent.java:159)
        at thinwire.render.web.ComponentRenderer.componentChange(ComponentRenderer.java:351)
        at thinwire.render.web.EventProcessor.processUserActionEvent(EventProcessor.java:132)
        at thinwire.render.web.EventProcessor.run(EventProcessor.java:88)
Caused by: java.net.SocketException: Unconnected sockets not implemented
        at javax.net.SocketFactory.createSocket(SocketFactory.java:97)
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:225)
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
        ... 13 more


I believe that this exception is being caused because I the Exchange Server is using the SSL Transport instead of an "ordinary" transport, because if I don't get the Transport from my Session (simply do a Transport.send()) I get the authentication failure.

I think I need to somehow get a Transport that will use the correct means (an instance of the com.sun.mail.smtp.SMTPSSLTransport class) to connect to the SMTP service. Is there any way to do this?

Please advise.
[Message sent by forum member 'factor3' (factor3)]

http://forums.java.net/jive/thread.jspa?messageID=267349