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.
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
- http://www.oracle.com/technetwork/java/javamail/javamail-138606.html
- http://www.coderanch.com/t/601387/java/java/smtp-error/
- http://stackoverflow.com/questions/2980408/problem-with-java-mail-no-provider-for-smtp/
- http://stackoverflow.com/questions/16861553/javax-mail-nosuchproviderexception-no-provider-for-smtps/
- https://answers.atlassian.com/questions/167299/unable-to-send-email-and-error-as-javax-mail-nosuchproviderexception/