← Back Home

JavaMail api - javax.mail.NoSuchProviderException: smtp

Problem

When you are using Java’s mailapi.jar, it also expects supporting libraries like smtp.jar, imap.jar, pop3.jar, gimap.jar, dsn.jar. If you are using Java EE platform, then it is already included. But if you are getting the following error, you might have to include additional libraries, from Java mail API.

Exception in thread "main" javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:746)
at javax.mail.Session.getTransport(Session.java:685)
at javax.mail.Session.getTransport(Session.java:628)
at javax.mail.Session.getTransport(Session.java:608)
at javax.mail.Session.getTransport(Session.java:663)
at javax.mail.Transport.send0(Transport.java:154)
at javax.mail.Transport.send(Transport.java:80)

There are several forums and discussions happening on this same issue. Surprisingly, this is a small class path issue.

Solution

To solve this error, make sure you have both mailapi.jar and smtp.jar in your classpath. Also, make sure you don’t have duplicate jar files in your class path.

Reading the FAQ on Oracle’s documentation will give you a better idea. http://www.oracle.com/technetwork/java/javamail/faq/index.html

References

comments powered by Disqus