File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Mail variables are not being resolved to a type ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Mail variables are not being resolved to a type !" Watch "Mail variables are not being resolved to a type !" New topic
Author

Mail variables are not being resolved to a type !

Mishaal Khan
Ranch Hand

Joined: Aug 21, 2008
Posts: 61
I am trying to use the code below to send an email using JSP , but for all the variables i.e

Session
MimeMessage
InternetAddress

its throwing exception that "cannot be resolve to a type " . I am using Eclipse and in build path it includes the classpath to mail.jar and activation.jar.

Here is the JSP code:

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host", "localhost");
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@hotmail.com");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");

Transport.send(message);
%>
<html>

A Message has been sent.
Check your inbox.


Click here to send another!


</html>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Why on earth would you do this in a JSP? Move the Java code to a Java class where it belongs.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: Mail variables are not being resolved to a type !