Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got bad greeting from SMTP host: smtp.yandex.ru, port: 465, response: [EOF]] with root cause Yandex

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("[email protected]");
    message.setTo("[email protected]");
    message.setSubject(null);
    message.setText("Hello World");
    emailSender.send(message);
    return "success send email " + now();
}

application.yml

host: smtp.yandex.ru
username: [email protected]
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

like image 962
dos4dev Avatar asked Feb 03 '26 17:02

dos4dev


1 Answers

With port: 465 (SMTP Protocol), you can try enable ssl via properties:

"mail.smtp.ssl.enable": true

mail.smtp.ssl.enable: If set to true, use SSL to connect and use the SSL port by default. Defaults to false for the "smtp" protocol and true for the "smtps" protocol.

Using spring boot, add properties to application.yml:

 mail:
   ...
   properties:
     "mail.smtp.ssl.enable": true

References:

Outgoing mail
mail server address — smtp.yandex.com
connection security — SSL
port — 465

The SMTP protocol provider supports the following properties: https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html

like image 167
huytmb Avatar answered Feb 05 '26 07:02

huytmb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!