wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Problem with mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Problem with mail" Watch "Problem with mail" New topic
Author

Problem with mail

visu Nekk
Ranch Hand

Joined: Sep 06, 2005
Posts: 122
Hai,

mport javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import javax.mail.*;

import javax.mail.internet.*; // important

import javax.mail.event.*; // important

import java.net.*;

import java.util.*;

public class MailServlet extends HttpServlet

{

public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException, IOException

{

PrintWriter out=response.getWriter();

response.setContentType("text/html");

try

{
Properties props = new Properties();
props.put("mail.smtp.host","localhost");
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("sender");
String s2 = request.getParameter("receiver");
String s3 = request.getParameter("subject");
String s4 = request.getParameter("area");
Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress(s1));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(s2,false));
message.setSubject(s3);
message.setText(s4);
Transport.send(message);
out.println("mail has been sent");

}

catch(Exception ex)

{

System.out.println("ERROR....."+ex);

}

}

}

i am calling this code from a jsp page.
But i am getting an error report as below.

javax.servlet.ServletException: Error instantiating servlet class com.choral.be.MailServlet
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)


root cause

java.lang.NoClassDefFoundError: javax/mail/Message
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:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Unknown Source)

I am unable to figure out the problem.Can anyone help me out.
Thanx in advance,
Regards,
Visu
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

java.lang.NoClassDefFoundError: javax/mail/Message

The JavaMail classes are missing in your classpath. Make sure mail.jar and activation.jar (and any other classes you might need for JavaMail) are in your classpath.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41591
    
  55
JavaMail is part of J2EE, for which we have a separate forum to which I'm moving this thread. Please continue the discussion here.


Ping & DNS - my free Android networking tools app
 
 
subject: Problem with mail