aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Send Email using Servlet 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 "Send Email using Servlet " Watch "Send Email using Servlet " New topic
Author

Send Email using Servlet

Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Hello java friend ,

currently i am working on java mail. I am trying to send email using servlet but i am facing lots of problems.

A normal Stand alone java mail program works.

But, if i embedded it in servlet application i got various errors even i have added all jars in it.

Here is my servlet program and my exceptions

Servlet Program ::


and here are the Exceptions i got ::



HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class emailpckg.EmailServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.NoClassDefFoundError: javax/mail/MessagingException
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:293)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Unknown Source)


Please help me friends. You may run my program on your system and tell me if you are facing problems or not .?

It requires in my project so only because of this email program i am not able to submit my project.!

Thanking you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

java.lang.NoClassDefFoundError: javax/mail/MessagingException

This means that you are missing the class javax.mail.MessagingException.

You'll have to include the required JAR files in the WEB-INF/lib directory of your web application, just like you put them on the classpath for a standalone application.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Amey Ambulgekar
Ranch Hand

Joined: Nov 22, 2011
Posts: 36
Jesper de Jong wrote:java.lang.NoClassDefFoundError: javax/mail/MessagingException

This means that you are missing the class javax.mail.MessagingException.

You'll have to include the required JAR files in the WEB-INF/lib directory of your web application, just like you put them on the classpath for a standalone application.



Hello Jesper de Jong,

if it is so they why my normal Standalone Program means without using Servlet is running.?

It should have also given such error('s). But it works fine only i have problem is, when i embedded with Servlet it gives me error.!

I have included all jars such as javaee-api-6.0.jar , mail.jar,smtp.jar,pop3.jar,activation.jar,mailapi.jar,dsn.jar,imap.jar..

Why don't you tried my program please.!

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

To run your standalone program you have to set up your classpath correctly. To run your servlet you have to set up your web application correctly. This has nothing to do with the code and everything to do with configuration. So it's perfectly possible to get one right and one wrong, and you've done that.

So whining for us to run your code is not useful, since it's the configuration which is the problem, not the code, and you haven't shown us your configuration.

If you're wondering what configuration I'm talking about, well, Jesper already told you what to do. It sounds like you decided to reject that advice and post that last unfortunate post instead.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Send Email using Servlet