gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:14:14 24 4
gpt4 key购买 nike

我正在尝试使用 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)

最佳答案

看起来 IBM JVM 对其接受的 SSL 证书的要求比 Eclipse 中的任何 JVM 都要严格。假设目标 SMTP 服务器在您的控制之下,您可以接受这是一件好事,并修复该服务器的证书链中存在的任何问题。 (或者如果问题实际上出在 Domino 服务器的证书链中,我猜这可能是提示,即使堆栈跟踪表明在从目标读取响应时抛出了异常,那么您可以在 Domino 的 key 环中解决问题。)如果这些都不是一个选项,那么您将不得不 - 我推荐这个 - 找到一种绕过 JVM 证书验证的方法。这是一个 link到一篇关于它的文章,带有示例代码。

关于java - 相同的代码,通过 Lotus Domino 发送电子邮件的不同行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33561189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com