I'm trying to set up my Java project to be able to send e-mail (via g-mail, if it matters) and am getting "javax.mail.NoSuchProviderException: No provider for smtps" every time I try to run the following line (which is copy/paste from their example).
Transport transport = session.getTransport("smtps");
I've looked around and found that this is generally thrown because you don't have the mail.jar included in your classpath, but I do in fact have the mail.jar included. Since I am running JDK 1.6 I do not need to include the activation.jar according to the FAQ here (http://www.oracle.com/technetwork/java/javamail/faq-135477.html#classpath). Further, the activation.jar does not seem to be present in version 1.4.7 of javamail.
Just in case something got corrupted, I re-downloaded the entire zip from oracle's website, extracted it and added the jar fresh (after deleting the old jar) and I am still getting the same error. Any thoughts as to what the issue could be at this point?
EDIT: Here is the full stack trace that is being printed:
javax.mail.NoSuchProviderException: No provider for smtps
at javax.mail.Session.getProvider(Session.java:433)
at javax.mail.Session.getTransport(Session.java:627)
at javax.mail.Session.getTransport(Session.java:608)
... my code that calls getTransport() ...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
... more of my code ...
at java.lang.Thread.run(Thread.java:662)
Just in case anyone makes the same mistake as I have: you have to use lowercase letters for the protocol resolving to work. If you type SMTP
as a protocol name instead of smtp
you will get the NoSuchProviderException
. It most likely works the same way for all other providers.
When you use Mail API make sure that which protocol are you expecting to work with? In this case you are missing smtp.jar with your eclipse project.
there are several jars for different protocols are available in mail api. EX: dsn.jar , gimap.jar , imap.jar ,mailapi.jar ,pop3.jar ,smtp.jar
So it turns out that the issue was that an outdated version of mail.jar was included in a project that I was referencing and, upon updating that copy of the mail.jar, the issue was resolved.
For future reference, is there any way to log or provide visibility on such jar conflicts?
https://confluence.atlassian.com/confkb/cannot-send-email-due-to-javax-mail-nosuchproviderexception-smtp-error-154079.html
Make sure that you have the javax.mail.jar in you build path. If you are using eclipse you may have to refresh or right click your project in the files explorer, select configure build path, add external JAR and then add it to the build path. Send email using java gives working code (I've tested it) in case you just want to look over yours. If that is not the problem, or you are not using eclipse, a stack trace would be nice
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With