Through painful experience, I’ve learned that most dummy SMTP servers you can use for integration tests do not support SSL. This is more than a little irritating if you want to automate testing for SSL connections. Fortunately, there is one dummy email server that I’ve found that actually supports just about any protocol you could want, including SSL: GreenMail.

The GreenMail examples are very helpful, but there is one more piece you need if you’re going to test sending email over an SSL connection:

Security.setProperty("ssl.SocketFactory.provider", DummySSLSocketFactory.class.getName());
GreenMail mailServer = new GreenMail(ServerSetupTest.SMTPS);
mailServer.start();

That first line of code prevents you from getting a giant SSLException stack trace when your email sending code tries to connect to the GreenMail dummy server. Thank you stackoverflow!