Код: Выделить всё
org.springframework.mail.MailSendException: Mail server connection failed.
Failed messages: jakarta.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
Код: Выделить всё
application.ymlКод: Выделить всё
spring:
mail:
host: smtp.gmail.com
port: 587
username: your_email@gmail.com
password: your_app_password
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
connectiontimeout: 5000
timeout: 5000
writetimeout: 5000
debug: true
Код: Выделить всё
private final JavaMailSender javaMailSender;
@Value("${app.mail.from}")
private String fromEmail;
public void sendMail(EmailRequest request) {
try {
System.out.println("From mail spotted -> " + fromEmail);
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(fromEmail);
message.setTo(request.getTo().toArray(new String[0]));
if (request.getCc() != null && !request.getCc().isEmpty()) {
message.setCc(request.getCc().toArray(new String[0]));
}
if (request.getBcc() != null && !request.getBcc().isEmpty()) {
message.setBcc(request.getBcc().toArray(new String[0]));
}
message.setSubject(request.getSubject());
message.setText(request.getBody());
javaMailSender.send(message);
log.info("Simple email sent successfully to: {}", request.getTo());
} catch (Exception e) {
log.error("error exception while sendmail", e);
throw new RuntimeException(e);
}
}
Код: Выделить всё
2026-05-18T10:07:26.234+05:30 ERROR 2684 --- [SERVICEB]
[nio-9898-exec-4] c.t.s.modules.mail.service.MailService :
error exception while sendmail
org.springframework.mail.MailSendException:
Mail server connection failed.
Failed messages:
jakarta.mail.MessagingException: Exception reading response;
nested exception is:
java.net.SocketException: Connection reset
- Хост SMTP — smtp.gmail.com
- Порт — 587
- STARTTLS включен
- Подключение к Интернету работает
Нужно ли мне использовать пароли приложения Gmail или изменить какую-либо конфигурацию SMTP?>