春季邮件。 javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接

时间:2018-07-30 06:28:15

标签: javamail

我通过端口上的协议smtp连接到邮件服务器,未进行加密。 我收到错误

"Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;\n  nested exception is:\n\tjavax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake. Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;\n  nested exception is:\n\tjavax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake"

我的豆子的配置

@Bean
public JavaMailSender javaMailService() {
    JavaMailSenderImpl javaMailSender = new JavaMailSenderImpl();
    javaMailSender.setHost(host);
    javaMailSender.setProtocol(protocol);
    javaMailSender.setUsername(from);
    javaMailSender.setPassword(password);
    javaMailSender.setPort(port);
    javaMailSender.setDefaultEncoding(encoding);
    Properties javaMailProperties = new Properties();
    javaMailProperties.put("mail.smtp.starttls.enable", "true");
    javaMailProperties.put("mail.smtp.auth", "true");
    javaMailProperties.put("mail.transport.protocol", "smtp");
    javaMailProperties.put("mail.debug", "true");
    javaMailProperties.put("mail.smtp.localhost", "127.0.0.1");
    javaMailProperties.put("mail.smtp.ssl.trust", "*");
    System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
    javaMailSender.setJavaMailProperties(javaMailProperties);

    return javaMailSender;
}

我可以说一个有效的方法。有什么问题吗?

2 个答案:

答案 0 :(得分:0)

需要删除javaMailProperties.put(“ mail.smtp.starttls.enable”,“ true”);

答案 1 :(得分:0)

关于客户端和服务器都支持哪些TLS版本或密码套件,可能存在分歧。例如,如果升级了JDK,则可能已更改。 Java Mail不使用https.protocols属性,但是如果出于其他原因需要设置该属性,则可能需要设置相应的JavaMail属性,例如mail.smtp.ssl.protocols

您可能需要按照SSLNOTES.txt中的调试提示来找出问题所在。