Solved

Java Mail error

Posted on 2003-11-21
16
336 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now