Solved

Java Mail error

Posted on 2003-11-21
16
341 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html form inside div 3 96
Struts tiles for layout structure along with Angular JS. 4 163
squirrelPlay java challenge 40 158
excpetion with multiple catch 11 116
How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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