• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

mail sending in jsp

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic