Joshcampbell7
Joshcampbell7

Reputation: 69

Could not convert socket to TLS Spring Mail

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";
}

Upvotes: 1

Views: 2089

Answers (1)

Kirsten Ali
Kirsten Ali

Reputation: 36

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

Upvotes: 1

Related Questions