wood burning stoves 2.0*
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

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

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

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

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.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());

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");

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


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

Joined: Jan 10, 2002
Posts: 60782

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

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Prasad Tamirisa:

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.


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)
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)
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
Similar Threads
Error in excel sending additional request
java mail
Preview the compose message
Error in excel sending additional request
Call a Servlet from JSP