GeeCON Prague 2014*
The moose likes Other JSE/JEE APIs and the fly likes Help with java mail. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Help with java mail." Watch "Help with java mail." New topic
Author

Help with java mail.

Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
i am trying to include the java mail functionality in my application.
i got an example for mailing. As an individual class with main it worked good. But i removed the main part of that program and made that as the function so that i can call that by passing the arguments. but i am getting javax.mail.NoSuchProviderException: No provider for smtps error.
i have included the code(what i made as function by just removing the main )

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
See http://java.sun.com/products/javamail/FAQ.html#gmail for an example of how to connect to Gmail; the "mail.transport.protocol" thing looks odd.


Ping & DNS - my free Android networking tools app
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
No did not get the solution.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

But presumably you modified your code based on what you read in the FAQ? If not, then you should. But now notice that we can't see the code you are asking about. Nor, for that matter, do we know what problem you are now having.
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Backtracked to my code posted above, getting the same error. javax.mail.NoSuchProviderException: No provider for smtps
What exactly it means " No provider for smtps" i have included all the jars.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
What do you mean by "backtracked" - that you're now again using the code you posted above? Why? What was the result of you reading and implementing the FAQ entry I pointed you to?
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
I tried to implement in the method given in FAQ. But it gave me an error i was really frustrated with all those errors and i deleted that program. So i am trying to implement in the way in which i started.
i need to know why javax.mail.NoSuchProviderException: No provider for smtps this exception raises?
Can someone please explain this?
Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
I tried to implement in the method given in FAQ. But it gave me an error i was really frustrated with all those errors and i deleted that program. So i am trying to implement in the way in which i started.

So now you're using code that you KNOW does not work, because you couldn't understand the code that purportedly does work? Did it occur to you to try and track down the problem (whichever that was) you had with that code?
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
No. I would like to know why its throwing that error.
The code works as a class with the main in it. But if i make it as a function and call it from another class then its throwing this error.
So i am trying to find out the reason for its behavior. (May be something i have missed) So need to know the reason.
Thanks
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Please do help in integrating java mail to my application.
i am getting the below error
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

What does session.getProviders() return? Is smtps one of the supported providers?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
It says no provider.



So what am i suppose to use for GMAIL?

Please help
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

You haven't even tried my advice, have you? Because that exception is definitely not thrown when you call getProviders().
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Hi Rob,
I did try that. in the list of providers SMTP,POP3 and IMAP are listed. But not the SMTPS.
That exception is thrown when the we call the getProvider is called.
Please advise what we have to use for gmail.
thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
I suspect that you would have long solved this problem if you had followed the advice I gave in my first post.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

If SMTPS is not one of the providers then no secure SMTP connections can be made at all. JAidev, have you tried updating your JavaMail libraries? Perhaps they are older versions that don't have SMTPS yet - mine do.
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Hi All,
I have two different code. The first code works fine. Its a class with main().

1st code

I can send the mail using this code.
When i remove the main and make the same code to be a function and call it from another function then i am getting this error javax.mail.NoSuchProviderException: smtps
Modified code (as a function)

Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
From debug i have noticed the resource file is getting loaded from the wrong place. Basically its not pointing to the new mail.jar(1.4.3).
First is the debug from the working code-
----
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
Here struts_1_0_2.jar,weblogic_modified.jar are used.
----
But in my code the resource is getting loaded from a different location.
DEBUG: not loading system providers in <java.home>/lib
DEBUG: not loading optional custom providers file: /META-INF/javamail.providers
DEBUG: successfully loaded default providers
I am using message.jar,mysql-connector-java-3.1.12.jar,struts_1_0_2.jar,weblogic_modified.jar in my application.
Is any of the jar file is creating the conflict?Both are running on the same eclipse but in different projects.
Please let me know.
Thanks
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Now its picking from the correct resource file after including the mail.jar and activation.jar to the classpath.
But now i am getting another exception.
error

Please help with the exception.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42039
    
  64
java.lang.NoClassDefFoundError: javax/net/ssl/SSLPeerUnverifiedException

Yikes! That class has been part of the JRE since Java 1.4; which JRE version are you using?
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
i am using JRE 1.6.0
Do i need to place jsse.jar in lib\ext folder?
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
Is anything missing in the classpath?
Jaidev Arer
Ranch Hand

Joined: Mar 12, 2010
Posts: 38
As mentioned earlier i have two codes.
One the independent code which works and another code which is the part of the application and this has an issue.
Today i used the System.out.println("classpath = " + System.getProperty("java.class.path")); to see what was in the classpath. i got two different output.
classpath for the working code


classpath for the application code

None of the jar file are present in the classpath.
Can someone please help with the reason for the strange behavior in picking the classpath.
Thanks
 
GeeCON Prague 2014
 
subject: Help with java mail.