Description

i encountered an issue when using spring-boot-starter-mail dependency. When the smtp client fails to connect to the configured host and port, it enters an infinite reconnection state impacting on MailHealthIndicator becoming stuck attempting to resolve the connection. This causes the /actuator/health endpoint to hang and never return a response

if monitoring tools or services are evaluationg /actuator/health endpoint, they may not indicate an HTTP status error but instead report a timeout. This makes it difficult to identify the real cause of failure

Steps to reproduce:

  1. configure mail properties with smpt settings that points to an unreachable host
  2. attempt to send an email using JavaMailSender

Expected behaviour:

Fail after a certain default time with an error message

Actual behaviour:

  • the application enters an infinite reconnection state trying to connect to the smtp server without logging meaningful errors or reaching a timeout
  • the /actuator/health endpoint hangs indefinitely

Suggestion:

provide a default timeout configuration that prevents the app from getting stuck in an infinite reconnection state

Environment:

  • Spring boot version: 3.3.3
  • Java version: 21
  • Mail server: Amazon SES SMTP

Hi, this is my first issue, hope its well structured.

Comment From: wilkinsona

We generally try to align our defaults with those of the underlying technology. In this case, that means an infinite timeout. We have documented a recommendation to configure custom timeouts:

In particular, certain default timeout values are infinite, and you may want to change that to avoid having a thread blocked by an unresponsive mail server