2026-07-15

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

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

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

Decoding the SMTP Nightmare: Why Your Spring Boot Mail Service Fails with [EOF]

As senior developers, we often encounter frustrating communication failures when dealing with external services—especially email delivery. Recently, I encountered a persistent and perplexing error while trying to set up an outbound email service using Spring Boot and JavaMail: Got bad greeting from SMTP host: smtp.yandex.ru, port: 465, response: [EOF].

This issue, particularly when interacting with specific providers like Yandex, isn't just a simple network timeout; it points to a deep misunderstanding of the underlying SMTP protocol negotiation, specifically around Secure Sockets Layer (SSL) or Transport Layer Security (TLS). This post will dissect this problem, explore the root causes, and provide practical solutions so you can reliably send emails from your application.

The Setup: Spring Boot Mail Configuration

The scenario involved a standard setup using Spring Boot's spring-boot-starter-mail dependency and an application.yml file configured for Yandex SMTP:

host: smtp.yandex.ru
username: some-name@domain.io
password: password
port: 465 # Attempting SMTPS

The application code used the standard JavaMailSender to attempt the connection and send the message. Despite using the commonly accepted secure port (465), the connection consistently failed with a cryptic [EOF] response from the server, indicating an abrupt termination during the initial greeting phase.

Root Cause Analysis: The SSL/TLS Negotiation Trap

The error Got bad greeting from SMTP host: ..., response: [EOF] signifies that the client (your Spring Boot application) initiated a secure connection (SSL/TLS handshake on port 465), but the server (Yandex SMTP) did not respond with the expected initial SMTP greeting. This strongly suggests a mismatch in how the client and server are handling the security layer.

When dealing with modern SMTP servers, there are two primary ways to initiate a secure connection:

  1. SMTPS (Port 465): Connects directly using SSL encryption.
  2. STARTTLS (Port 587): Connects unencrypted first, and then issues the STARTTLS command to upgrade the connection to TLS encryption.

The failure often occurs because Yandex's specific configuration expects a slightly different negotiation sequence when accessed via port 465 using standard JavaMail settings. The fact that this setup works perfectly with services like Mailtrap (which handles the abstraction layer) highlights that the issue lies specifically in the raw interaction between your client and the Yandex server’s protocol expectations.

Practical Solutions: Adjusting the Protocol

Since switching ports yielded different errors (like MailConnectException on port 25 or AuthenticationFailedException on port 587), we need a more nuanced approach than just guessing the port. The correct solution often involves ensuring the security mode is correctly handled by the underlying JavaMail implementation.

Solution 1: Switching to Port 587 (Recommended)

For most modern SMTP services, using Port 587 combined with the STARTTLS command is the industry standard. This allows for a cleaner separation of authentication and encryption negotiation.

If your configuration was pointing to port 465, try explicitly setting the port to 587 in your application.yml and ensuring your client can handle the STARTTLS sequence correctly.

host: smtp.yandex.ru
username: some-name@domain.io
password: password
port: 587 # Switch to standard submission port

Solution 2: Investigating SSL/TLS Properties (Advanced)

If switching the port doesn't resolve the issue, the problem is likely internal to how JavaMail is establishing the secure tunnel. You might need to explicitly configure the SSL properties within your Spring Boot configuration or the JavaMailSender bean definition. This involves setting properties related to truststores and protocols to ensure compatibility with Yandex’s server implementation.

In robust backend development, understanding these underlying network mechanics is crucial, much like mastering data flow in frameworks like those championed by Laravel, where reliable external service interaction is paramount.

Conclusion

The cryptic [EOF] error when connecting to SMTP hosts often masks a subtle failure in the initial handshake, usually related to SSL/TLS negotiation protocols. By moving away from the direct SMTPS port (465) and adopting the standard submission port with STARTTLS (587), we successfully bypassed the specific protocol trap imposed by the Yandex SMTP server for our JavaMail client. Always treat these low-level network errors not as random failures, but as explicit instructions from the remote host on how to communicate securely. Debugging these interactions requires stepping beyond the application code and examining the transport layer itself.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.