使用JavaMail通过SMTP(STARTTLS)发送消息时,会引发以下异常:
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.ArrayIndexOutOfBoundsException
这里(关于stackoverflow)和其他地方的多个帖子表明邮件传输会话的一些属性,即
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.ssl.trust","*");
在解决这个问题中发挥作用,但我尝试了所有这些参数的组合(存在/不存在),没有一个能解决问题。
有人知道如何解决这个问题吗?
其他信息/详细信息:
Java版本:1.6.0
JavaMail版本:1.5.2
邮件传输会话的属性:
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host","XXX");
props.put("mail.smtp.port","587");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.ssl.trust","*");
props.put("mail.smtp.user","XXX");
props.put("mail.smtp.password","XXX");
props.put("mail.smtp.connectiontimeout","60000");
props.put("mail.smtp.timeout","600000");
props.put("mail.smtp.writetimeout","60000");
调试JavaMail的输出(在引发异常之前):
DEBUG: JavaMail version 1.5.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.
MTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Mi
rosystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,
mtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax
mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: need username and password for authentication
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "XXX", port 587, isSSL false
220 bsmtp.bon.at ESMTP (1)
DEBUG SMTP: connected to host "XXX", port: 587
EHLO ZZZ
250-bsmtp.bon.at
250-PIPELINING
250-SIZE 104857600
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250 8BITMIME
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "104857600"
DEBUG SMTP: Found extension "ETRN", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "8BITMIME", arg ""
STARTTLS
220 2.0.0 Ready to start TLS
异常的完整堆栈跟踪:
javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLException: java.lang.ArrayIndexOutOfBoundsException
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1999)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:709)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at com.safebook.MailMessage.send(MailMessage.java:144)
at com.safebook.MailMessage.send(MailMessage.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.ibm.jscript.types.JavaAccessObject.call(JavaAccessObject.java:321)
at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)
at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)
at com.ibm.jscript.ASTTree.ASTAssign.interpret(ASTAssign.java:91)
at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100)
at com.ibm.jscript.ASTTree.ASTTry.interpret(ASTTry.java:109)
at com.ibm.jscript.std.FunctionObject._executeFunction(FunctionObject.java:261)
at com.ibm.jscript.std.FunctionObject.executeFunction(FunctionObject.java:185)
at com.ibm.jscript.std.FunctionObject.call(FunctionObject.java:171)
at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)
at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)
at com.ibm.jscript.ASTTree.ASTIf.interpret(ASTIf.java:85)
at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)
at com.ibm.jscript.types.FBSGlobalObject$GlobalMethod.call(FBSGlobalObject.java:280)
at com.ibm.jscript.types.FBSObject.call(FBSObject.java:161)
at com.ibm.jscript.types.FBSGlobalObject$GlobalMethod.call(FBSGlobalObject.java:219)
at com.ibm.jscript.ASTTree.ASTCall.interpret(ASTCall.java:197)
at com.ibm.jscript.ASTTree.ASTBlock.interpret(ASTBlock.java:100)
at com.ibm.jscript.ASTTree.ASTTry.interpret(ASTTry.java:109)
at com.ibm.jscript.ASTTree.ASTProgram.interpret(ASTProgram.java:119)
at com.ibm.jscript.ASTTree.ASTProgram.interpretEx(ASTProgram.java:139)
at com.ibm.jscript.JSExpression._interpretExpression(JSExpression.java:435)
at com.ibm.jscript.JSExpression.access$1(JSExpression.java:424)
at com.ibm.jscript.JSExpression$2.run(JSExpression.java:414)
at java.security.AccessController.doPrivileged(AccessController.java:448)
at com.ibm.jscript.JSExpression.interpretExpression(JSExpression.java:410)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:251)
at com.ibm.jscript.JSExpression.evaluateValue(JSExpression.java:234)
at com.ibm.xsp.javascript.JavaScriptInterpreter.interpret(JavaScriptInterpreter.java:222)
at com.ibm.xsp.binding.javascript.JavaScriptMethodBinding.invoke(JavaScriptMethodBinding.java:111)
at com.ibm.xsp.component.UIViewRootEx.initBeforeContents(UIViewRootEx.java:1621)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.initComponent(AbstractCompiledPage.java:333)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createTree(AbstractCompiledPage.java:256)
at com.ibm.xsp.page.compiled.AbstractCompiledPage.createViewRoot(AbstractCompiledPage.java:167)
at com.ibm.xsp.application.ViewHandlerExImpl._createViewRoot(ViewHandlerExImpl.java:521)
at com.ibm.xsp.application.ViewHandlerExImpl.createViewRoot(ViewHandlerExImpl.java:567)
at com.ibm.xsp.application.ViewHandlerExImpl.doCreateView(ViewHandlerExImpl.java:142)
at com.ibm.xsp.application.ViewHandlerEx.createView(ViewHandlerEx.java:90)
at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:251)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by:
javax.net.ssl.SSLException: java.lang.ArrayIndexOutOfBoundsException
at com.ibm.jsse2.o.a(o.java:26)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:340)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:225)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:367)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:32)
at com.ibm.jsse2.SSLSocketImpl.startHandshake(SSLSocketImpl.java:95)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:543)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:480)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1994)
... 64 more
Caused by:
java.lang.ArrayIndexOutOfBoundsException
at com.ibm.crypto.provider.yc.a(Unknown Source)
at com.ibm.crypto.provider.yc.a(Unknown Source)
at com.ibm.crypto.provider.yc.a(Unknown Source)
at com.ibm.crypto.provider.TlsMasterSecretGenerator.engineGenerateKey(Unknown Source)
at javax.crypto.KeyGenerator.generateKey(Unknown Source)
at com.ibm.jsse2.kb.b(kb.java:114)
at com.ibm.jsse2.kb.a(kb.java:138)
at com.ibm.jsse2.lb.a(lb.java:113)
at com.ibm.jsse2.lb.a(lb.java:120)
at com.ibm.jsse2.kb.t(kb.java:227)
at com.ibm.jsse2.kb.a(kb.java:425)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:785)
at com.ibm.jsse2.SSLSocketImpl.h(SSLSocketImpl.java:675)
at com.ibm.jsse2.SSLSocketImpl.a(SSLSocketImpl.java:669)
... 68 more
可能您的JavaMail库(mail.jar或javax.mail.jar)太旧了。从此处下载最新版本:https://javaee.github.io/javamail/
JDK的SSL支持似乎出了问题。也许来自服务器的证书的某些东西让它感到困惑。您使用的是相当旧的JDK版本。我会尝试升级到当前版本,看看这是否可以解决问题。您还可以尝试在JDK中启用一些低级SSL调试输出,如JavaMail SSLNOTES. txt中的链接所述。
问题内容: 我编写了以下代码,用于通过SMTP作为TLS使用javamail API通过SMTP发送电子邮件,因为不支持SSL,但最终出现以下异常。请在下面查看我的代码。我使用了调试模式,在代码下面也可以找到异常。 异常跟踪 谁能帮我调试一下吗?提前致谢! 问题答案: 我通过评论以下属性解决了这个问题 并且代码执行时没有错误或警告,或者只是从上述源代码中删除了这一行。到现在为止,它就像是一种魅力。
我编写了以下代码,用于通过SMTP使用javamail API发送电子邮件,因为SSL不受支持,但最终出现以下异常。请看下面我的代码。我使用了调试模式,在代码下面你也可以找到异常。 异常跟踪 有人能帮我调试一下吗?提前感谢!
我有另一个转换套接字异常。Stackoverflow将我和相关答案联系起来,我已经做了人们建议的所有事情。 这里有异常描述: 线程“main”javax中出现异常。邮政MessaginException:无法将套接字转换为TLS;嵌套的例外是:java。网SocketException:java。安全NoSuchAlgorithmException:在com上构造实现时出错(算法:Default,
我已经将证书导入了cacerts(JAVA\u HOME指向的地方),但仍然出现了这个错误。无法解决问题。客户端的邮件服务器(Microsoft ESMTP服务器)没有防火墙问题。我可以从我的服务器远程登录。已尝试SSLpoke,但超时。试过25号端口的tcpdump,可以看到来回的通信。基本上是试图触发来自邮件服务器的出站电子邮件。 详细的错误日志为: 原因:javax。邮政MessaginEx
我在使用Apache Commons Mail连接到SMTP服务器时遇到问题。我已经尝试了所有方法,但我唯一能在网上找到的是Java邮件。这是我的错误: 原因:javax.mail.MessagingException:无法将套接字转换为TLS;嵌套异常是:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorExc
我有一个java程序(从谷歌复制的)可以使用office365 SMTP发送电子邮件,它作为一个独立的java程序运行良好,但当我在web应用程序的中将这个java程序部署为jar文件,并从JSP调用该方法时,它抛出了以下错误: 有人能分享一下他们对这个问题的看法吗。java代码: