我正在尝试使用javamail发送电子邮件, 在我的本地计算机上运行课程时,邮件很好发送。
在生产计算机上我收到错误:
Caused by: javax.mail.MessagingException: Could not convert socket to TLS (java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl))
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1230)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:378)
at javax.mail.Service.connect(Service.java:271)
at javax.mail.Service.connect(Service.java:91)
at javax.mail.Service.connect(Service.java:76)
at javax.mail.Transport.send(Transport.java:94)
... 8 more
Caused by: java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at javax.net.ssl.DefaultSSLSocketFactory.throwException(SSLSocketFactory.java:179)
at javax.net.ssl.DefaultSSLSocketFactory.createSocket(SSLSocketFactory.java:199)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:249)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1226)
... 13 more
Caused by: java.security.NoSuchAlgorithmException: Error constructing implementation (algorithm: Default, provider: SunJSSE, class: com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
at java.security.Provider$Service.newInstance(Provider.java:1245)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:220)
at sun.security.jca.GetInstance.getInstance(GetInstance.java:147)
at javax.net.ssl.SSLContext.getInstance(SSLContext.java:125)
at javax.net.ssl.SSLContext.getDefault(SSLContext.java:68)
at javax.net.ssl.SSLSocketFactory.getDefault(SSLSocketFactory.java:102)
at com.sun.mail.util.SocketFetcher.startTLS(SocketFetcher.java:247)
... 14 more
Caused by: java.io.IOException: Invalid keystore format
at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:633)
at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38)
at java.security.KeyStore.load(KeyStore.java:1185)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.getDefaultKeyManager(DefaultSSLContextImpl.java:150)
at com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl.<init>(DefaultSSLContextImpl.java:40)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at java.security.Provider$Service.newInstance(Provider.java:1221)
... 20 more
在安全路径中有以下文件:
68595 Mar 9 2009 cacerts
2221 Mar 9 2009 java.policy
9937 Mar 9 2009 java.security
132 Mar 9 2009 javaws.policy
2940 Mar 9 2009 _local_policy.jar
2481 Feb 28 12:54 local_policy.jar
2469 Mar 9 2009 _US_export_policy.jar
2465 Feb 28 12:54 US_export_policy.jar
没有trusted.certs文件。
生产使用jdk 1.6.0_13,有可能某些文件太旧了吗? Anoter详细说明每个东西在生产中都运行良好,直到上个星期一(7月30日)代码中没有任何变化,现在我收到了这个错误。
很难弄清楚出了什么问题,因为我甚至不知道哪个文件存在问题。 如果您有任何想法我会接受它!
感谢您的帮助!
答案 0 :(得分:1)
最后问题是管理员定义了自定义keyStore:
-Djavax.net.ssl.keyStore = xxxxxxx.p12
它错过了这个:
-Djavax.net.ssl.keyStoreType = PKCS12
答案 1 :(得分:0)
尝试打开密钥库文件时似乎失败了。通常,密钥库文件在运行应用程序的用户的主目录中名为“.keystore”。如果这个文件在上周一更新,这将解释为什么你的程序开始失败。请注意,您可以通过设置javax.net.ssl.keyStore系统属性来覆盖密钥库文件的默认位置,因此也请检查它。
问题可能是由您的信任存储引起的,可以通过javax.net.ssl.trustStore属性设置。
更多信息位于JSSE Reference Guide。