Thursday, May 05, 2005

Java Mail and Google Search API

On one of the projects I'm involved with, we use Java Mail for sending e-mail and the Google search API for indexing our pages. These seemingly unrelated components are in fact connected.

For the longest time we were seeing javax.mail.NoSuchProviderException: No provider for smtp type exceptions. My searches told me that this was most likely because of either a mis-match between my mail.jar and activation.jar files or that I had duplicates of either. I was positive neither was the case. Finally, I removed the JAR files and the code still compiled. We must have had a duplicate after all. After putting together a Perl script to search all the JARs on my classpath, I found that the google-api.jar was in fact the culprit. It includes both the mail and activiation frameworks. So for anyone else who happens to come across this same problem and then subsequently comes across this page (i.e. nobody), now you know what to do.


smita said...

Hello Martin,
I am facing the same problem as you faced. would you please let me know how you solved this problem?
Did you remove both the jars (mail ant activation) from classpath?
I tried removing mail.jar, but mail.jar has some configuration files in the META-INF folder which are not there in the META-INF of google.jar.
I would be highly obliged if you please let us know on this page how you solved the problem.

Martin Davidsson said...

Hey Smita,

I did as I described above, namely I removed the Mail and Activiation related classes from the google.jar file. To do so, I extracted the class files (jar -xf google.jar), removed the relevant classes, and then re-created the jar file (jar -cf google.jar *). I could be off on the jar command's syntax. Does that not help your issue?

smita said...

I removed entire javax\mail and javax\activation folder from googleapi.jar. but still getting the same exception. you removed class by class files?

Martin Davidsson said...

Odd, I would think that should do it. I don't think I have the Perl script I mentioned anymore, but that might be another debugging technique you could try. For all the .jar files in your classpath, list the classes (jar -tf file.jar) and see where the activation/mail classes show up.

smita said...

dont know where the problem is.
I have a test application having only mail.jar and activation.jar.
This works well...if I inlcude googleapi.jar in this application, then also it is working well.
But if I add mail.jar in my existing application then it is showing excpetion. really strange.

Cyllan said...

Hi all,
I know that this article is a few old, but man, i finished my career final proyect thanks to it and i want to give you my thanks.
I really appreciate the help that you provided to my companion and me with this article.



Martin Davidsson said...

Thanks for the kind words and glad it helped you out!