aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes java.lang.ClassNotFoundException: javax.mail.Message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "java.lang.ClassNotFoundException: javax.mail.Message" Watch "java.lang.ClassNotFoundException: javax.mail.Message" New topic
Author

java.lang.ClassNotFoundException: javax.mail.Message

Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Hi all,

I am running jsp, Servlet example to send Mail through Java Mail API.
In my JSP page i set all the info like to, from,subject and msg Body Then i sumbit my form to "Mail.servlet" Servlet. On redirect of Servlet i got following Exception.

Jul 2, 2011 12:23:10 AM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet mailservlet as unavailable
Jul 2, 2011 12:23:10 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet mailservlet
java.lang.ClassNotFoundException: javax.mail.Message
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1116)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

I am using MyEclipse 8.5, JRE 1.6.13 and Tomcat 6.0. As per Exception I add javax.mail JAR in my class path and also try add it in WEB-INF/Lib folder and redeploy whole application and then also try but i get same exception, So please do me Help as Possible as Fast.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

This doesn't sound like a missing class issue, but rather like a configuration issue. It appears that Tomcat doesn't like how "mailservlet" is defined in the web.xml. Please post the web.xml.


JBoss In Action
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Peter Johnson wrote:This doesn't sound like a missing class issue, but rather like a configuration issue. It appears that Tomcat doesn't like how "mailservlet" is defined in the web.xml. Please post the web.xml.


This is my WEB.XML file


Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Double-check the capitalization of the mailservlet class; the web.xml has it all in lower case and that doesn't seem right.

If that doesn't help, post the full contents of the WAR file. You can do that by running "jar -tf xxx.war" where xxx.war is the name of your war file (you might need to supply the full path to the war).
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Peter Johnson wrote:Double-check the capitalization of the mailservlet class; the web.xml has it all in lower case and that doesn't seem right.

If that doesn't help, post the full contents of the WAR file. You can do that by running "jar -tf xxx.war" where xxx.war is the name of your war file (you might need to supply the full path to the war).


Hay Peter thanking you for showing interest in my problem.

any how i solve class not found exception but now i face following Exception while sending mail.


following is my mailservlet.java

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
Session session1 = Session.getDefaultInstance(props,null);
String s1 = request.getParameter("text1");
String s2 = request.getParameter("text2");
String s3 = request.getParameter("text3");
String s4 = request.getParameter("area1");
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);

Exception throwing on executing Transport.send(message).

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at crud.mailservlet.doPost(mailservlet.java:66)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

Check whether you have connectivity to the Gmail's smtp server.

Try telnet smtp.gmail.com 25

Regards
Santhosh
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

According ot the following, you are using the wrong port:
http://mail.google.com/support/bin/answer.py?answer=13287
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Santhosh ayiappan wrote:Check whether you have connectivity to the Gmail's smtp server.

Try telnet smtp.gmail.com 25

Regards
Santhosh


I tried it but it also generates same Exception
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Peter Johnson wrote:According ot the following, you are using the wrong port:
http://mail.google.com/support/bin/answer.py?answer=13287


I checked given site its give different port for gmail.
but in our program i give only SMTP host and port is set automatically, so there is any way for changing port ??
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

Use the below to change the port #.
property.put("mail.smtp.port", portNumber);
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Santhosh ayiappan wrote:Use the below to change the port #.
property.put("mail.smtp.port", portNumber);


As per your suggestion i tried to set different port Number but still it throws same exception

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1270)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:275)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at crud.mailservlet.doPost(mailservlet.java:65)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Santhosh ayiappan
Ranch Hand

Joined: Jan 30, 2007
Posts: 80

Which port are you using now ?

Try telnet for that port. If the telnet does not work, there is issue with the network connectivity.

~Santhosh
Jitu Modi
Greenhorn

Joined: Jul 01, 2011
Posts: 10
Santhosh ayiappan wrote:Which port are you using now ?

Try telnet for that port. If the telnet does not work, there is issue with the network connectivity.

~Santhosh


I tried port no. 465,587 as per peters suggestion, but when i run it takes default port 25. I also use telnet. Following is LOC in which i specify port and smtp server.

Properties props = new Properties();
props.put("mail.smtp.host", "smtp.telnet.com");
props.put("mail.smtp.port", 465);
---
---
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5843
    
    7

Jitu Modi wrote:As per your suggestion i tried to set different port Number but still it throws same exception

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 25, response: -1

Um, the error message says you are still trying to use port 25...
 
 
subject: java.lang.ClassNotFoundException: javax.mail.Message