Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Exception in thread "main" javax.mail.NoSuchProviderException:



I was using this tutorial to write a basic JavaMail program using JSSE that makes a connection to a mail server and lists imap folders. I used the code for the DummySSLSocketFactory class in this tutorial to create a custom SSLSocketFactory that accepts all certificates without validation. I was able to successfully run my program from the command line using a shell script

JAVAHOME=/opt/java
export JAVAHOME
CLASSPATH=".:activation.jar:commons-logging.jar:jdom.jar:mail.jar:mstor.jar:javamaildir-0.4pre9.jar"
export CLASSPATH

cd "`dirname $0`"

exec "${JAVAHOME}/bin/java" -Xmx2048m imaptest

When I import my project into NetBeans I'm able to compile successfully, but I get the following error when I try to run it

Exception in thread "main" javax.mail.NoSuchProviderException: No provider for imaps

this is because NetBeans is not finding the DummySSLSocketFactory class and is not able to set the Property

            Security.setProperty("ssl.SocketFactory.provider",
                    "DummySSLSocketFactory");

I need to make the DummySSLSocketFactory class available to my code in NetBeans. By placing the DummySSLSocketFactory.class in the same directory as my code, I was able to run it from the command line, but NetBeans is not able to see it. I've tried adding the DummySSLSocketFactory.class to my package, and I've tried creating a jar file from this .class file and adding it to my project libs, but I'm getting the same error.

Thanks for any advice, I'd be happy to provide any other information.