Author
mail sending in jsp
sravani
Greenhorn
Joined: Dec 06, 2008
Posts: 4
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
Joined: Oct 27, 2005
Posts: 19216
"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.
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35253
posted Dec 06, 2008 11:37:00
0
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.
Android apps – ImageJ plugins – Java web charts
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
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.
subject: mail sending in jsp