oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.
https://jodd.org
BSD 2-Clause "Simplified" License
4.06k stars 724 forks source link

Better support for STARTTLS #210

Closed petromir closed 9 years ago

petromir commented 9 years ago

It's very difficult to understand how to configure SmtpSslServer in order to use STARTTLS. I managed to find a way by setting the following property mail.smtp.socketFactory.class to empty string. Мoreover everything else throws exceptions. (e.g. javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection). Default value of this property is javax.net.ssl.SSLSocketFactory.

It would be great if you implement more convenient way for setting STARTTLS properly and add documentation for it.

igr commented 9 years ago

Sure!!

Can you please send me your code, just want to see how did you use it; so we can model the interface in the best way?

petromir commented 9 years ago

This how I my code looks like:

SmtpSslServer smtpServer = SmtpSslServer.create("xxx", 587)
   .authenticateWith("xxx", "xxx")
   .property("mail.smtp.socketFactory.class", "");

According to this post http://stackoverflow.com/a/414396, mail.smtp.socketFactory.class shouldn't be present, and I'm not sure whether you should remove it at all or just set it to empty string.

I see it something like this:

SmtpSslServer smtpServer = SmtpSslServer.create("xxx", 587)
   .authenticateWith("xxx", "xxx").
   .startTlsRequired(true) // Similar to Apache Commons Email
   .setDebug(true) // Should set 'mail.debug' - very useful for debugging.
igr commented 9 years ago

Just a question - would you mind if TLS is set on by default? Just to keep backward compatibility, so you can use either:

which one would be better in your opinion? Maybe the first one?

btw, just added debug flag ;)

petromir commented 9 years ago

After thorough reading of Apache Commons Email sources and Java Mail settings (https://javamail.java.net/nonav/docs/api/com/sun/mail/smtp/package-summary.html) I think that it would be nice if you think about the following stuff:

I saw that Jodd Mail sets implicitly mail.smtp.starttls.enable to true, and I'm not sure if it's good idea do expose only one of the STARTTLS settings.

Sorry if I have misled you with my previous code proposal.

igr commented 9 years ago

No problem, I will just add few of these methods... stay tuned, will send some code soon.

igr commented 9 years ago

Did exactly how you proposed it :) Thank you for your time, I really appreciate!

petromir commented 9 years ago

Thanks for the fast response. I will be glad if you suggest me some nice Java mock mail server :)

igr commented 9 years ago

I am on the same search as well ;) For now, I think I will use GreenMail in my tests; but havent tried it yet.

petromir commented 9 years ago

Thanks.It looks promising. I will try it along with its the competitors.