1.java通过imap协议去操作邮件(其实啥协议无所谓,只是这里用的是imap)
报错:No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Exception in thread "main" javax.mail.MessagingException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate);
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at com.doublefs.mall.datamonitor.controller.base.BaseController.main(BaseController.java:53)
Caused by: javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at java.base/sun.security.ssl.HandshakeContext.<init>(HandshakeContext.java:171)
at java.base/sun.security.ssl.ClientHandshakeContext.<init>(ClientHandshakeContext.java:98)
at java.base/sun.security.ssl.TransportContext.kickstart(TransportContext.java:223)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:392)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:371)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:549)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:354)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:116)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:115)
at com.sun.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:685)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:636)
... 3 more
本地是mac是正常的,上云之后开始报错一开始以为是端口问题后来看了aws是支持的
https://docs.aws.amazon.com/workmail/latest/userguide/using_IMAP.html
然后开始找解决方案,看了以下这些
https://stackoverflow.com/questions/67899129/postfix-and-openjdk-11-no-appropriate-protocol-protocol-is-disabled-or-cipher/67901142#67901142
https://superuser.com/questions/1649382/upgrade-from-openjdk-11-0-7-to-11-0-11-causes-sslhandshakeexception-no-appropri
也参考了
https://blog.csdn.net/jarniyy/article/details/51315665
https://blog.csdn.net/weixin_43650943/article/details/118578264
https://blog.csdn.net/luoww1/article/details/52571971
最后搜到了
https://stackoverflow.com/questions/41649693/property-mail-imap-starttls-enable-true-doesnt-work
更新jar包即可解决
最终解决问题的jar
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
---------问题重现---------
1.引入问题的jar
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
2.同时修改
Security.setProperty("jdk.tls.disabledAlgorithms","SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL")
就可以复现问题
记得set之前先get一下存好最后如有必要可以恢复
---------问题重现---------
其他:
1.本地之所以没有报错是因为
Security.getProperty("jdk.tls.disabledAlgorithms")
输出
"SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL"
2.本地先设置有问题的disabledAlgorithms然后可以复现报错,设置为正常的就可以解决但是云上后来也设置过本地不报错的disabledAlgorithms
Security.setProperty("jdk.tls.disabledAlgorithms","SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL")
但是也没有生效,这个问题没有去追,不方便操作
解决时间:4个小时,一开始没有留意jar包问题,解了个寂寞呀........