Reputation: 491
I'm trying to send an email where the values are dependent on the values from the form in the Frontend, but they are always null.
Controller
@PostMapping("/send")
public void sendEmail(Contact contact) throws MessagingException {
SimpleMailMessage mailMessage = new SimpleMailMessage();
mailMessage.setTo("[email protected]");
mailMessage.setSubject(contact.getSubject()); //This is always null
mailMessage.setFrom("[email protected]");
mailMessage.setText("To confirm ationToken()););");
emailSenderService.sendEmail(mailMessage);
}
Entity
public class Contact {
private String email;
private String address;
private String subject;
private String content;
public Contact() { }
//...getters & setters
Result Subject not being displayed.
Any suggestions of where i've gone wrong and how i could correct this are much appreciated.
Upvotes: 0
Views: 110
Reputation: 7504
Prepend method parameter with @RequestBody
annotation as below:
public void sendEmail(@RequestBody Contact contact) throws MessagingException {
Upvotes: 1