File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mail sending in jsp

 
sravani
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

i used the below code to send an email. When i run the below code i got the errors.
[jsp]

<%@ page import="java.util.Properties " %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="java.net.InetAddress.*" %>
<%@ page import="javax.mail.Transport.*" %>
<%@ page import="javax.mail.Message.RecipientType.*" %>
<%
String host="smtp.eminosoft.com";
String from="me@example.com";
String to="mymail@gmail.com";
Properties prop=System.getProperties();
prop.put("mail.smtp.host",host);
Session ses1=Session.getDefaultInstance(prop,null);
MimeMessage msg=new MimeMessage(ses1);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject("urgent Message");
msg.setText("you won the lottery");
Transport.send(msg);
%>
[/jsp]

i placed the mailapi.jar,mail.jar,pop3.jar,smtp.jar in Apache Software Foundation\Tomcat 5.5\webapps\test\WEB-INF\lib.


i got the below errors

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
Session cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
Session cannot be resolved

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
MimeMessage cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
MimeMessage cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
InternetAddress cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
Message.RecipientType.TO cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
InternetAddress cannot be resolved to a type

An error occurred at line: 10 in the jsp file: /mailsend.jsp
Generated servlet error:
Transport cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



please advice that whats the problem in my code.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sravani eeee",

Welcome to the ranch. However, you seem to have missed our naming policy. Can you please change your name accordingly?

Thank you,

Rob


Now, back to your problem. The imports seem to be in place, so are you sure you have the JavaMail JAR files in your JSP's classpath?

Moving to the JSP forum.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The syntax of the imports is incorrect. Individual classes are not imported as "java.net.InetAddress.*" but as "java.net.InetAddress". The asterisk notation is for importing all classes in a package.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or for all internal classes. "import java.net.InetAddress.*;" compiles just fine in both Java 1.4 and Java 6.

But yeah, you got a point. It does miss the import of java.net.InetAddress itself.

Still, that class does not get mentioned in the error, but classes that should have been imported with javax.mail.* (which includes javax.mail.Transport) and javax.mail.internet.* are. So I'm still saying: class path problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic