este es el html
Código
<form id="contact-form" class="contact-form" method="POST" th:action="@{/send}"> <div class="row"> <div class="col-md-6"> <div class="form-group"> <input type="text" class="form-control" name="NAME" placeholder="Name" th:required="true"> </div> </div> <div class="col-md-6"> <div class="form-group"> <input type="email" class="form-control" name="EMAIL" placeholder="Email" th:required="true"> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <input type="text" class="form-control" name="SUBJECT" placeholder="Subject"> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <textarea class="form-control" name="MESSAGE" placeholder="Message" rows="3"></textarea> </div> </div> </div> <input type="hidden" name="_next" value=""> <input type="hidden" name="_captcha" value="false"> <div class="row"> <div class="col-md-12"> <button type="submit" class="btn mybtn2" id="botonEnviar">enviar mensaje</button> </div> </div> </form> ... </body> <script type="text/javascript"> $(document).ready(function() { $.ajax({ type:"post", data:str, url:"/send/mail", dataType: "json", success: function(result){ $(element).append(result); } }) }); </script> </html>
y el metodo del controlador
Código
@Controller public class MailController { @Autowired private MailService mailService; @PostMapping("/sendl") @ResponseBody throws MessagingException { HttpHeaders headers = new HttpHeaders(); headers.add("Custom-Header", "mail"); + "\nMessage: " + message; mailService.sendMail(email, "beginnerweb@hotmail.com", subject, mensaje); return message; } }