无法将套接字转换为 TLS Spring Mail

发布于 2025-01-09 01:50:58 字数 1425 浏览 1 评论 0原文

我收到错误: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东风软 2025-01-16 01:50:58

我今天遇到了同样的问题。我的防病毒软件出了问题。暂时禁用 Avast 后,邮件发送器按预期工作。

I experienced the same problem today. My antivirus was at fault. After temporarily disabling Avast the mail sender worked as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文