Как обработать форму обратной связи в Spring?

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title></title>
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>


<header th:insert="bloks/header-admin :: header"></header>


<body class="text-center">

<main class="form-signin w-25 m-auto">
    <form>
        <img class="mb-4" src="https://static.vecteezy.com/ti/vecteur-libre/p1/2775409-pharmacie-pharmacie-vector-logo-vectoriel.jpg" alt="" width="150" height="140">
        <h1 class="h3 mb-3 fw-normal">Please sign in</h1>

        <div class="form-floating m-auto">
            <input type="email" class="form-control" id="floatingInput" placeholder="[email protected]">
            <label for="floatingInput">Email address</label>
        </div>
        <div class="form-floating">
            <input class="form-control" id="floatingPhone" placeholder="phone" type="text">
            <label for="floatingPhone">Phone</label>
        </div>
        <div class="form-floating">
            <input class="form-control" id="floatingName" placeholder="your name" type="text">
            <label for="floatingName">name</label>
        </div>
        <div class="form-floating">
            <textarea class="form-control" id="ms" placeholder="Your order" type="text"></textarea>
            <label for="ms">Your order</label>
        </div>
        <br>
        <button class="w-100 btn btn-lg btn-primary" type="submit">Send</button>
        <p class="mt-5 mb-3 text-muted">© 2017–2022</p>
    </form>
</main>





</body>
<footer th:insert="bloks/footer :: footer"></footer>

Вот у меня есть форма как мне сделать чтобы данные с нее отправляли на определеный email ? У меня просто не отправляет

Значение которое принимает email

 public class Email {

    private String email;
    private String name;
    private String phone;
    private String massage;
    private String allForm;


    public Email() {
    }

    public Email(String email, String name, String phone, String massage, String allForm) {
        this.email = email;
        this.name = name;
        this.phone = phone;
        this.massage = massage;
        this.allForm = "Name : " + name + "\n" + "Phone : " + phone + "\n" + "Email :" + email + "\n" + "Message : " + massage;
    }

    public String getAllForm() {
        return allForm;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMassage() {
        return massage;
    }

    public void setMassage(String massage) {
        this.massage = massage;
    }
}

Логика для отпраки по почте

public class Sender {

    private final String username;
    private final String password;
    private final Properties props;

    public Sender(String username, String password) {
        this.username = "username";
        this.password = "password";

        props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
    }

    public void send(String subject, String text, String fromEmail, String toEmail){
        Session session = Session.getDefaultInstance(props, new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

        try {
            Message message = new MimeMessage(session);
            //от кого
            message.setFrom(new InternetAddress(username));
            //кому
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail));
            //тема сообщения
            message.setSubject(subject);
            //текст
            message.setText(text);

            //отправляем сообщение
            Transport.send(message);
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

Написал такую логику контролеру

@PostMapping("/buy")
    public String itemBuy(@RequestParam String email1,@RequestParam String name,@RequestParam String phone,@RequestParam String massage,  Model model){
        Sender sender = new Sender("[email protected]","12345678");
        Email emailSender = new Email();
        emailSender.setEmail(email1);
        emailSender.setName(name);
        emailSender.setPhone(phone);
        emailSender.setMassage(massage);
        sender.send("Order: ", emailSender.getAllForm(), "[email protected]", emailSender.getEmail());

        return "redirect:/shop";
    }

И вот получаю значение как мне добавить почту №1 с которой будет отправляться мне письмо на почту №2?


Ответы (0 шт):