I use brand new spring boot project with next Maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
Implementation of method
@Autowired
JavaMailSender emailSender;
@GetMapping("/send")
public String send() {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom("some-name@domain.com");
message.setTo("toReceiver@gmail.com");
message.setSubject(null);
message.setText("Hello World");
emailSender.send(message);
return "success send email " + now();
}
application.yml
host: smtp.yandex.ru
username: some-name@domain.io
password: password
port: 465
And receive the next exception
2020-08-03 23:02:35.102 ERROR 21615 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.yandex.com, port: 465, response: [EOF].
Failed messages: javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.yandex.com, port: 465, response: [EOF]; message exceptions (1) are: Failed message 1: javax.mail.MessagingException: Got bad greeting from SMTP host: smtp.yandex.com, port: 465, response: [EOF]] with root cause
But the same code works perfectly with Mailtrap service
According to this link I used not secure 25 port After which I received the next exception
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.yandex.ru, 25; timeout -1;
587 port =
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: [EOF];
I guess a problem with SSL
Similar issue
This properties help me
spring:
boot:
admin:
mail:
to: ${spring.mail.username}, test@yandex.ru
from: ${spring.mail.username}
mail:
host: smtp.yandex.ru
username: test@yandex.ru
password: password
port: 587
protocol: smtp
properties:
"mail.transport.protocol": smtp
"mail.smtp.auth": true
"mail.smtp.starttls.enable": true