Getting "MessagingException: Could not convert socket to TLS" when sending mail via SMTP
Looks like something is going wrong in the JDK's SSL support. Perhaps something about the certificate from the server is confusing it. You're using a pretty old version of the JDK. I would try upgrading to a current version to see if that resolves the problem. You can also try enabling some of the low level SSL debugging output in the JDK, as described in the links in the JavaMail SSLNOTES.txt.
xpages-noob
Updated on June 04, 2022Comments
-
xpages-noob almost 2 years
When using JavaMail to send a message via SMTP (+STARTTLS) the following exception is raised:
javax.mail.MessagingException: Could not convert socket to TLS; nested exception is: javax.net.ssl.SSLException: java.lang.ArrayIndexOutOfBoundsException
Multiple posts here (on stackoverflow) and elsewhere suggest that some properties for the mail transport session, namely
props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.ssl.trust","*");
play a role in solving this issue, but I have tried all combinations of those parameters (present / absent), and none of them solves the problem.
Does anybody have an idea how to fix this?
Additional Information / Details:
Java version: 1.6.0
JavaMail version: 1.5.2
Properties for mail transport session:
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");
Debug output from JavaMail (before Exception is raised):
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
Full stacktrace for the exception:
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