dev@glassfish.java.net

V3 and KeyStorePassword

From: Annies <annies_a_at_yahoo.com>
Date: Mon, 24 Nov 2008 13:49:07 -0800 (PST)

Hi

I am writing a simple test application with the attached index.jsp.
When I run this, I get


javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25;
  nested exception is:
        java.net.SocketException: Unconnected sockets not implemented
I debugged this and the root cause seems to be missing keystore password.
When I edited my domain.xml and added the following line, everything works perfectly.

        <jvm-options>-Djavax.net.ssl.keyStorePassword=changeit</jvm-options>


Isn't this something that should be taken care automatically?
P.S: Please replace test_at_gmail.com/password with valid values.


Thanks
Annies




<%_at_page contentType="text/html" pageEncoding="UTF-8"%>
<%_at_page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Test Email</h2>
    </body>
    
    <%
           Properties props = new Properties();
           props.put("mail.smtp.host", "smtp.gmail.com");
           props.put("mail.smtp.auth", "true");
           props.put("mail.smtp.user", "test_at_gmail.com");
           props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
           props.setProperty("mail.smtp.socketFactory.fallback", "false");
           props.setProperty("mail.smtp.port", "25");
           props.setProperty("mail.smtp.socketFactory.port", "465");

           java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
           System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
                                  
           Session s = Session.getInstance(props, new PasswordAuth());
                            
           InternetAddress from = new InternetAddress("test_at_gmail.com");
           InternetAddress to = new InternetAddress("test_at_gmail.com");

           MimeMessage message = new MimeMessage(s);
           message.setFrom(from);
           message.addRecipient(Message.RecipientType.TO, to);
           message.setSubject("Subject");
           message.setText("Body");

           Transport.send(message);
    %>
   
   <%!
        private class PasswordAuth extends Authenticator {
            @Override
             protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("test_at_gmail.com", "password");
             }
        }
   %>

</html>