• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 354
  • Last Modified:

Java Mail error

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
rajnaik
Asked:
rajnaik
  • 8
  • 3
  • 2
  • +2
1 Solution
 
TimYatesCommented:
 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
 
rajnaikAuthor Commented:
hi TimYates,

i tried this but it won't work.

raj.
0
 
rajnaikAuthor Commented:
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!

 
TimYatesCommented:
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
 
rajnaikAuthor Commented:
>>  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
 
TimYatesCommented:
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
 
kennethxuCommented:
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
 
yapsingCommented:
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
 
rajnaikAuthor Commented:
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
 
rajnaikAuthor Commented:
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
 
rajnaikAuthor Commented:
hi yapsing,

removed that also but it can't be helpful.

raj
0
 
rajnaikAuthor Commented:
hi yapsing,

removed that also but it can't be helpful.

thanks,
raj
0
 
kennethxuCommented:
>> 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
 
rajnaikAuthor Commented:
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
 
CetusMODCommented:
PAQed, with points refunded (250)

CetusMOD
Community Support Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now