I'm trying to create an email notification when a user fills in a form, but I'm not trying very well:
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 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