1
I’m trying to create a notification via email when a user fills in a form, but I’m not very lucky:
Mail server Connection failed; nested Exception is javax.mail.Messagingexception: Could not Convert socket to TLS; nested Exception is: javax.net.ssl.Sslhandshakeexception: Remote host closed Connection During Handshake. Failed messages: javax.mail.Messagingexception: Could not Convert socket to TLS; nested Exception is: javax.net.ssl.Sslhandshakeexception: Remote host closed Connection During Handshake
@PostMapping("submit")
public ModelAndView submit(@Valid Faq faq, @RequestParam("myFile") MultipartFile myFile, BindingResult bindingResult, RedirectAttributes redirectAttr, Locale locale, @AuthenticationPrincipal UserImpl activeUser) throws IOException {
if (bindingResult.hasErrors()) {
return new ModelAndView("/index");
} else {
faqService.save(faq, myFile);
faqService.sendMessage(faq, activeUser.getUser());
redirectAttr.addFlashAttribute("message", messages.get("field.saved"));
}
return new ModelAndView("redirect:/faq/question");
}
method in the controller
public void sendMessage(Faq faq, User user) {
SimpleMailMessage mail = new SimpleMailMessage();
if (faq != null || user != null) {
if(user.getEmail() != null || user.getName() != null || faq.getQuestion() != null || faq.getAnswer() != null) {
if(user.getEmail().contains("@") ){
mail.setTo("[email protected]");
mail.setFrom("[email protected]");
mail.setSubject("Nova pergunta");
mail.setText(
"Prezado(a) Administrador " + ", \n\n" + "esta pergunta foi "
+ faq.getQuestion() + "' foi cadastrado no sistema!\n");
javaMailSender.send(mail);
}
}
}
}
Service
It appears to be related to this: https://stackoverflow.com/a/17799656/6370247
– Saulo Junior