相同的代码,通过Lotus Domino发送电子邮件的不同行为

时间:2015-11-06 06:59:02

标签: java ssl javamail lotus-domino sslhandshakeexception

我正在尝试使用SSL在端口465上发送电子邮件。 在Eclipse中的独立应用程序中运行,一切运行良好。 在Domino Java Agent中运行我收到了SSLHandshakeException。下面你可以看到代码和SSLHandshakeException。

Lotus Domino版本8.5.1 FP5

你能帮我理解问题是什么吗?

    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();
        }
    }

在Domino Java Agent中运行我遇到了这个错误:

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)

2 个答案:

答案 0 :(得分:1)

看起来IBM JVM对它接受的SSL证书比对Eclipse中的JVM更严格。假设目标SMTP服务器在您的控制之下,您可以接受这一点,并解决该服务器证书链中存在的任何问题。 (或者,如果问题实际上是在Domino服务器的证书链中,我猜可能是抱怨,即使堆栈跟踪指示在从目标读取响应时抛出异常,那么您可以解决Domino&中的问题#39; s密钥环。)如果这些都不是一个选项,那么你必须 - 而且我推荐这个 - 找到绕过JVM证书验证的方法。这是一篇关于该文章的link,带有示例代码。

答案 1 :(得分:-1)

根据this可以关闭SSL检查。

在第一次发送后重启Domino服务器(将失败,但将禁用SSL)

谢谢理查德