• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with mail

 
visu Nekk
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15219
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaMail is part of J2EE, for which we have a separate forum to which I'm moving this thread. Please continue the discussion here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic