bbottema/simple-java-mail

Add access to the underlying javax.mail.Session properties

nclemeur opened this issue · 4 comments

I had a case where the connection to the smtp server was hanging and never returning. It seems to be linked to the fact no value for the timeout parameters was is given when building the session. The parameters are mail.smtp.timeout and mail.smtp.connectiontimeout and there is currently no easy way to set these.

One option is to use the Mailer constructor with the Session argument, but then it fails on a NPE in logSession because the transportStrategy is not set. Also, a lot of the setup work has to be redone using this approach.

I think a better approach, would be to provide another arguments to the Mailer constructor, adding a Properties argument which would allow for full customisation of the session properties.

I agree. Furthermore, as a fallback scenario I'm going to provide access to the internal Session object.

I've added applyProperties(Properties) and getSession() to Mailer's API.

Released in 2.3

code tells me to let you guys know why we are using "getSession()" - I am using it since the configuration of TLS access on port 587 is far more than easy. You guys are doing a perfect job where I am confident to re-use it at any place in my application, especially with the log4j-SMTPAppender.

Code I use:
return MailerBuilder.withSMTPServer(getSMTPHost(), TLS_PORT, getSMTPUsername(), getSMTPPassword())
.withTransportStrategy(TransportStrategy.SMTP_TLS)
.buildMailer()
.getSession();

Thanks @sYbb12, that's great to hear!