This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes Problem in sending a mail from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in sending a mail from a servlet" Watch "Problem in sending a mail from a servlet" New topic
Author

Problem in sending a mail from a servlet

Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
Hi Ranchers,

I am developing a servlet which will send email... i am calling a java class from that servlet which will take care of sending the mail. But when i am trying it as standalone its working fine, but trying from a servlet its giving problem like throwing .
Javax.activation.DataSource class is not found.
But i have added all the jars required for that.. incuding javax.action.*

What may be the problem??

Thaks and regards in advance...
[ May 14, 2008: Message edited by: Bear Bibeault ]
shankar reddy
Ranch Hand

Joined: Jun 04, 2007
Posts: 71
I hope it will work if you add activation.jar file.


Java Lover<br /> <br />Shankar Reddy <br />SCJP1.4 (88%)
Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
i have done that also ,not only i added that jar to web-inf lib but also to tomcat lib....... but at the last same problem................ it is giving exception at this line...........

MimeMessage message = new MimeMessage(session);
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
Hi.. could you copy paste the code?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Arun Kumar Gaddam:
i have done that also ,not only i added that jar to web-inf


You put it in 'web-inf' or you put it in 'WEB-INF'?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Hi,

It would be helpful if you can post the code which you have used.


Regards,
Durga Prasad
Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
Ok ill post the code........


//Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
//Adding required properties to send an email
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.gmail.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
//props.put("mail.debug", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");

System.out.println("Added all properties ..........\n");

//Creating an session object
System.out.println("==== 1 =====");
//javax.mail.Session sess = javax.mail.Session.getDefaultInstance(props,new Authenticate());
javax.mail.Session sess = javax.mail.Session.getInstance(props,new Authenticate());
//session.setDebug(true);

System.out.println("==== 2 =====");

//Creating an transport object
Transport transport = sess.getTransport();

InternetAddress addressFrom = new InternetAddress(_userName);

javax.mail.Message message = new MimeMessage(sess);------>1

System.out.println("Created an mimemessage obj........\n");
InternetAddress _to=new InternetAddress(email);


message.setRecipient(RecipientType.TO, _to);
message.setSubject("YOUR PASSWORD");
message.setContent(_emailMessageText, "text/html");
//message.addRecipients(Message.RecipientType.TO,_to);

System.out.println("Message obj ready to transport.....\n");

transport.connect();
transport.send(message);
transport.close();

System.out.print(" \nSuccess, Email sent to "+email);

System.out.println("<============== After sending to SendEmail class ============>\n");
System.out.println("Email Sent ....");*/

RequestDispatcher rd = request.getRequestDispatcher("successemail.jsp");
rd.forward(request, response);




Its throwing exception at line ------->1
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61308
    
  66

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
Thats ok sorry for not using code tags.....

here is my code please help me......
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Prasad Tamirisa:
Hi,

It would be helpful if you can post the code which you have used.


If the original poster is having a problem with a class not found exception, and has already stated that his code is working in a stand alone application, how would posting his code help?
karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
The three jars needed to send mail with your code are activation.jar, mailapi.jar and smtp.jar. Of these 3 jars only activation.jar contains javax.activation.DataSource.

Hence kindly ensure you have copied it in the correct WEB-INF/lib. [There may be a chance you are copying it into yet another web application's WEB-INF/lib.


http://www.skillassert.com


Arun Kumar Gaddam
Ranch Hand

Joined: May 05, 2007
Posts: 58
now its another one.........

its giving......

java.lang.SecurityException: SHA1 digest error for javax/mail/Authenticator.class
sun.security.util.ManifestEntryVerifier.verify(Unknown Source)
java.util.jar.JarVerifier.processEntry(Unknown Source)
java.util.jar.JarVerifier.update(Unknown Source)
java.util.jar.JarVerifier$VerifierStream.read(Unknown Source)
sun.misc.Resource.getBytes(Unknown Source)
java.net.URLClassLoader.defineClass(Unknown Source)
java.net.URLClassLoader.access$100(Unknown Source)
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1345)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
java.lang.ClassLoader.loadClassInternal(Unknown Source)
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
java.lang.Class.getConstructor0(Unknown Source)
java.lang.Class.newInstance0(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in sending a mail from a servlet