Этот стартер включает все необходимые зависимости и настройки, делая процесс отправки писем простым и понятным.
// Добавь зависимость:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
// Настрой параметры почты в application.properties (или application.yml):
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=my_email@gmail.com
spring.mail.password=my_password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
// Используй JavaMailSender в коде:
...
@Autowired
private JavaMailSender mailSender;
public void sendEmail(String to, String subject, String text) {
SimpleMailMessage message = new SimpleMailMessage();
message.setTo(to);
message.setSubject(subject);
message.setText(text);
message.setFrom("your_email@gmail.com");
mailSender.send(message);
}
...
👉 Java Portal
