-1

I'm trying to send an email on port 465 with SSL. Running in a stand-alone application in Eclipse, everything works well. Running in a Domino Java Agent I'm getting an SSLHandshakeException. Below you can see the code and SSLHandshakeException.

Lotus Domino Release 8.5.1 FP5

Can you help me understand what's the problem?

    private static final Object SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

    public static void main(String[] args) {
        final String username="username";
        final String password="password";
        Properties prop=new Properties();
        prop.put("mail.smtp.auth", "true");
        prop.put("mail.smtp.host", "xxx");
        prop.put("mail.debug", new Boolean("true").toString()); 
        prop.put("mail.smtp.port", "465");
        prop.put("mail.smtp.ssl.enable", "true");
        prop.put("mail.smtp.starttls.enable", "false");
        prop.put("mail.smtp.socketFactory.fallback", "false");
        prop.put("mail.smtp.socketFactory.class", SSL_FACTORY); 

        Session session = Session.getDefaultInstance(prop,
                new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });
        try {
            String htmlBody = "<strong>TEST</strong>";
            String textBody = "This is a Text Message.";
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("a@b.com"));
            message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("xxx@yyy.com"));
            message.setSubject("Testing Subject");
            MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
            mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
            mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
            mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
            mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
            mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
            CommandMap.setDefaultCommandMap(mc);
            message.setText(htmlBody);
            message.setContent(textBody, "text/html");
            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }

Running in a Domino Java Agent I got this error:

javax.mail.MessagingException: Exception reading response;   nested  
   exception is:  javax.net.ssl.SSLHandshakeException: com.ibm.jsse2.util.g:  
   Violated path length constraints
   at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
   at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
   at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
   at javax.mail.Service.connect(Service.java:297)
   at javax.mail.Service.connect(Service.java:156)
   at javax.mail.Service.connect(Service.java:105)
   at javax.mail.Transport.send0(Transport.java:168)
   at javax.mail.Transport.send(Transport.java:98)
   at JavaAgent.NotesMain(JavaAgent.java:60)
   at lotus.domino.AgentBase.runNotes(Unknown Source)
   at lotus.domino.NotesThread.run(Unknown Source)
   Caused by: 
     javax.net.ssl.SSLHandshakeException: com.ibm.jsse2.util.g: Violated path   length constraints
   at com.ibm.jsse2.n.a(n.java:36)
   at com.ibm.jsse2.sc.a(sc.java:154)
   at com.ibm.jsse2.gb.a(gb.java:89)
   at com.ibm.jsse2.gb.a(gb.java:283)
   at com.ibm.jsse2.hb.a(hb.java:260)
   at com.ibm.jsse2.hb.a(hb.java:171)
   at com.ibm.jsse2.gb.n(gb.java:140)
   at com.ibm.jsse2.gb.a(gb.java:123)
   at com.ibm.jsse2.sc.a(sc.java:320)
   at com.ibm.jsse2.sc.g(sc.java:198)
   at com.ibm.jsse2.sc.a(sc.java:478)
   at com.ibm.jsse2.e.read(e.java:7)
   at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
   at java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
   at java.io.BufferedInputStream.read(BufferedInputStream.java:248)
   at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
   at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
Andrea Baglioni
  • 303
  • 1
  • 2
  • 20
  • 1
    I don't think it's the source of your problem, but you don't need the [socket factory properties](http://www.oracle.com/technetwork/java/javamail/faq/index.html#commonmistakes). It looks like the IBM Java runtime is unhappy with the SSL certificate. I have no idea why. Perhaps there's a way to get additional debugging output from the IBM SSL implementation, like there is with the Oracle JDK? – Bill Shannon Nov 06 '15 at 07:34

2 Answers2

1

It looks like the IBM JVM is being more strict about SSL certificates that it accepts than whatever JVM you have in Eclipse. Assuming the destination SMTP server is under your control, you can accept this as a good thing and fix whatever problem exists in that server's certificate chain. (Or if the problem is actually in the Domino server's certifcate chain, which I guess might be the complaint even though the stacktrace indicates the exception was thrown while reading the response from the destination, then you could fix the problem in Domino's keyring.) If neither of those is an option, then you would have to - and I am not recommending this - find a way to bypass the JVM's certificate validation. Here's a link to an article about that, with sample code.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
-1

According to this is possible to turn off SSL check.

Restart Domino server after the first send (that will fail, but will disable SSL)

Thanks Richard

Andrea Baglioni
  • 303
  • 1
  • 2
  • 20