Solved

Java Mail error

Posted on 2003-11-21
16
339 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How To Remove a Principal from HttpServletRequest 4 40
java.util.concurrent.locks in java 3 186
grep code 4 176
thymeleaf natural templating vs JSP 2 69
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

19 Experts available now in Live!

Get 1:1 Help Now