Solved

Java Mail error

Posted on 2003-11-21
16
347 Views
Last Modified: 2010-04-01
Hello all experts,

Please help me to solve the problem.

I to build a JSP page which is capable to send an e-mail. for this i used javamail, but i'm getting error while sending e-mail through the JSP page.
the error is as follows:

org.apache.jasper.JasperException: smtp
      at org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
      at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
      at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
      at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:261)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:360)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:604)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:562)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:679)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
      at java.lang.Thread.run(Thread.java:536)


root cause

javax.servlet.ServletException: smtp
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(Unknown Source)
      at org.apache.jsp.simplemail1_jsp._jspService(simplemail1_jsp.java:96)
      at org.apache.jasper.runtime.HttpJspBase.service(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.jasper.servlet.JspServletWrapper.service(Unknown Source)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(Unknown Source)
      at org.apache.jasper.servlet.JspServlet.service(Unknown Source)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
      at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardContext.invoke(Unknown Source)
      at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.valves.AccessLogValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(Unknown Source)
      at org.apache.catalina.core.StandardPipeline.invoke(Unknown Source)
      at org.apache.catalina.core.ContainerBase.invoke(Unknown Source)
      at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:261)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:360)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:604)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:562)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:679)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
      at java.lang.Thread.run(Thread.java:536)

 

my jsp code is as follows:

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*, javax.activation.*" %>
<%
try
{
  Properties props = new Properties();
  props.put("mail.smtp.host", "smtp.server");
  props.put("mail.smtp.auth", "true");

  Session s = Session.getInstance(props,null);

  MimeMessage message = new MimeMessage(s);

  InternetAddress from = new InternetAddress("me@example.com");
  message.setFrom(from);
  InternetAddress to = new InternetAddress("you@example.com");
  message.addRecipient(Message.RecipientType.TO, to);

  message.setSubject("Test from JavaMail.");
  message.setText("Hello from JavaMail!");
  message.setSentDate(new Date());

  // Send the message
  Transport trans = s.getTransport("smtp");
  trans.connect("smtp.server", username, password);
  trans.sendMessage(message, message.getAllRecipients());
  trans.close();
%>
<html>
<p align="center">A Message has been sent.<br>Check your inbox.</p>
<p align="center"><a href="sendmail1.jsp">Click here to send another!</a></p>
</html>
<%
}catch(Exception ex)
{
  out.println(ex.getMessage());
  ex.printStackTrace ();
  out.println("<html><body>");
  out.print("An ananymous error occured while sending mail.");
  out.println("</body></html>");
}
%>

please help me to solve the problem.

thanks,
raj.

0
Comment
Question by:rajnaik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
  • +2
16 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9797532
 props.put("mail.smtp.host", "smtp.server");
  props.put("mail.smtp.auth", "true");

Should be:

  props.put( "mail.host", "ip or hostname for your SMTP server" ) ;
  props.put( "mail.transport.protocol", "smtp");

You need to fill in the server name or ip address of the SMTP server you want to use for sending mail...

Tim
0
 

Author Comment

by:rajnaik
ID: 9797889
hi TimYates,

i tried this but it won't work.

raj.
0
 

Author Comment

by:rajnaik
ID: 9797900
hi TimYates,

i tried this but it won't work.
getting the same error.

raj.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 9797903
different exception?

I'm pretty sure your exception is because;

>  props.put("mail.smtp.host", "smtp.server");

smtp.server is not a valid hostname or ip address?

Tim
0
 

Author Comment

by:rajnaik
ID: 9797936
>>  props.put("mail.smtp.host", "smtp.server");
>smtp.server is not a valid hostname or ip address?

actually the server name is different that i'm using(here is just an example), which is the same as provided by service provider to configure outlook. so the error might be different.

raj
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9797982
Hmmmm...  this seems to say you are doing it right:

http://oldlook.experts-exchange.com/Web/Web_Languages/JSP/Q_20322561.html

And adds something about authentication...
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9799137
look at the code that you have posted, you shouldn't be getting ServletException in the page, because you have catched exception yourself and print it out.
Are you sure that the code you posted is actully the one been running?
0
 
LVL 1

Expert Comment

by:yapsing
ID: 9801308
try removing:
>> props.put("mail.smtp.auth", "true");
might help... i used the same coding minus the code above and it worked fine. what is it for anyway?
0
 

Author Comment

by:rajnaik
ID: 9802767
hi TimYates,

>http://oldlook.experts-exchange.com/Web/Web_Languages/JSP/Q_20322561.html

tried this also but getting the same error.

thanks
raj
0
 

Author Comment

by:rajnaik
ID: 9802772
hi kennethxu,

the code is the same except the try & catch block is putted in commet when running. this is for getting the exact exception.

thanks,
raj
0
 

Author Comment

by:rajnaik
ID: 9802787
hi yapsing,

removed that also but it can't be helpful.

raj
0
 

Author Comment

by:rajnaik
ID: 9802789
hi yapsing,

removed that also but it can't be helpful.

thanks,
raj
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9806311
>> this is for getting the exact exception
hmm, the servlet engine will wrap the exception so you actually didn't get the EXACT one, you try/catch was good to determine the exact exception. the exact exception might help use to determine the problem.

if you would like to see the exception in web page instead of server stderr, you can use:
ex.printStackTrace ( new PrintWriter( out ) );
0
 

Author Comment

by:rajnaik
ID: 9838102
hi all,

the problem is solved. the prolem is basically due to the server policy of autheticating a user. the server on which the web site is hosted needs Log onto pop server first as security protocol and then they will allow to send the mails.

thanks all of you for trying to help...

raj
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10882485
PAQed, with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project in eclipse 11 62
dateFashion java challenge 9 153
squirrelPlay java challenge 40 160
Looking for some programs to resell or buy source codes 1 79
Determining the an SCCM package name from the Package ID
The goal of this blog is: - To define the incident management process - To go over the key elements of an incident management system - To look into incident alert management tools that integrate with ConnectWise.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question