bbottema/simple-java-mail

Maintenance: Let Mailer implement AutoCloseable, so it shuts down the connection pool automatically when disposed of by Spring

lburja opened this issue · 3 comments

lburja commented

When using the connection pool (batch-module enabled), the documentation suggests that the application should call mailer.shutdownConnectionPool() to allow the JVM to shut down.

With Spring Boot (spring-module), beans that implement AutoClosable are normally automatically handled and their close() method is called by the Spring framework upon application shutdown (see Spring documentation).

Therefore, I would expect Mailer to implement AutoClosable, and shut down the connection pool in the close() method, so that shutdown can be automatically handled by Spring Boot (also try-with-resources)

try-with resource would not be possible in combination with async emails; the connection pool might shut down before the email was sent. However, for closing applications from Spring perspective, this is an interesting thought.

Without too much testing this, I've added and released this in 8.1.3. Give it a spin!

lburja commented