Search code examples
javajakarta-mail

How does the static Transport.send() method manage its connections?


I have a question about the static javax.mail.Transport.send(Message msg) method. The documentation only says "Note that send is a static method that creates and manages its own connection". Does it mean that the method also closes the connection? What's the difference with the non-static sendMessage(Message msg, Address[] addresses) method?

I have had a couple of errors in production due to bad syntax email addresses passed by the glassfish 3 server turns really slow. I want to discard any connection leaks.


Solution

  • The static method opens the connection, sends the message, and closes the connection. And yes, the connection is also closed if there's an exception sending the message.