无法将套接字转换为 TLS Spring Mail
我收到错误: org.springframework.mail.MailSendException:邮件服务器连接失败;嵌套异常是 javax.mail.MessagingException: 无法将套接字转换为 TLS; 嵌套异常是: javax.net.ssl.SSLHandshakeException:没有适当的协议(协议已禁用或密码套件不合适)。失败消息:javax.mail.MessagingException:无法将套接字转换为 TLS; 电子邮件发送者服务类:
@Service
public class EmailSenderService {
@Autowired
private JavaMailSender mailSender;
public void sendEmail(String toEmail,
String subject,
String body){
SimpleMailMessage message=new SimpleMailMessage();
message.setFrom("[email protected]");
message.setTo(toEmail);
message.setText(body);
message.setSubject(subject);
mailSender.send(message);
System.out.println("Mail Sent Successfully...");
}
邮件控制器:
@Autowired
EmailSenderService emailSenderService;
@RequestMapping("/mail")
public String sendMail(HttpSession session, Model model){
emailSenderService.sendEmail("[email protected]","Test","This is the body of the test email");
session.setAttribute("mailMessage", "Check your email");
return "redirect:/dashboard";
}
I am getting the errors:
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS;
nested exception is:
javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate). Failed messages: javax.mail.MessagingException: Could not convert socket to TLS;
Email sender service class:
@Service
public class EmailSenderService {
@Autowired
private JavaMailSender mailSender;
public void sendEmail(String toEmail,
String subject,
String body){
SimpleMailMessage message=new SimpleMailMessage();
message.setFrom("[email protected]");
message.setTo(toEmail);
message.setText(body);
message.setSubject(subject);
mailSender.send(message);
System.out.println("Mail Sent Successfully...");
}
Mail Controller:
@Autowired
EmailSenderService emailSenderService;
@RequestMapping("/mail")
public String sendMail(HttpSession session, Model model){
emailSenderService.sendEmail("[email protected]","Test","This is the body of the test email");
session.setAttribute("mailMessage", "Check your email");
return "redirect:/dashboard";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我今天遇到了同样的问题。我的防病毒软件出了问题。暂时禁用 Avast 后,邮件发送器按预期工作。
I experienced the same problem today. My antivirus was at fault. After temporarily disabling Avast the mail sender worked as expected.