我连接到邮件服务器的协议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的配置
@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;
}
我可以在它起作用之前说一句。会出什么问题呢?
发布于 2018-07-31 04:18:37
对于客户端和服务器都支持哪些TLS版本或密码套件,可能存在分歧。例如,如果您升级了JDK,情况可能会发生变化。JavaMail不使用https.protocols
属性,但如果出于其他原因需要设置该属性,则可能需要设置相应的JavaMail属性,例如mail.smtp.ssl.protocols
。
您可能需要遵循SSLNOTES.txt中的调试技巧来找出问题所在。
发布于 2018-07-30 19:25:44
需要移除javaMailProperties.put("mail.smtp.starttls.enable","true");
https://stackoverflow.com/questions/51588133
复制相似问题