Hello Raffi,
It simply seems to be the problem of classpath. You have to include
JavaMail and JSDK jar files in your project classpath properties.
Regards,
Rashid.
----- Original Message -----
From: Raffiudeen Illahideen <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 09, 1999 1:48 PM
Subject: UNDEFINED PACKAGE, http, servlet, internet and mail..HELP!!
> Hi Folks:
> I was trying to execute the folowing program under the Visual J++ MS
> Developer Studio: I got the errors like:
>
> C:\JavaWebServer2.0\servlets\EmailServlet.java(25,8) : error J0051:
> Undefined package 'mail'
> C:\JavaWebServer2.0\servlets\EmailServlet.java(26,8) : error J0051:
> Undefined package 'internet'
> C:\JavaWebServer2.0\servlets\EmailServlet.java(28,8) : error J0051:
> Undefined package 'servlet'
> C:\JavaWebServer2.0\servlets\EmailServlet.java(29,8) : error J0051:
> Undefined package 'http'
> Error executing jvc.exe.
> EmailServlet.class - 4 error(s), 0 warning(s)
> WHAT COULD BE WRONG? ANY HELP IS HOGHLY APPRECIATED. I HAVE IIS-2 MPWS AND
> JSDK 1.2 IN MY MACHINE. I DON'T KNOW HOW TO RUN THIS CODES UNDER THE
> JDK1.2......PLEASE HELP!! THANKS
> THE PROGRAM I WAS TRYING IS:
> *****************************************************************
> import java.io.*;
> import java.net.InetAddress;
> import java.util.Properties;
> import java.util.Date;
>
> import javax.mail.*;
> import javax.mail.internet.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class EmailServlet extends HttpServlet
> {
> // Set to true to enable debug messages
> private static boolean debug = false;
>
> // Returns the HTML form used to send the email message
> public void doGet( HttpServletRequest req, HttpServletResponse res )
> throws ServletException, IOException
> {
> // Get the PrintWriter from the response object
> PrintWriter out = res.getWriter();
>
> // Output the HTML form used to send the email message
> out.println( "<html><head><title>Email
Servlet</title></head>" );
> out.println( "<body><center><h1>Email Servlet</h1>" );
> out.println( "<p>You must enter a value for all of the
fields which aren't
> marked as optional<br>" );
> out.println( "The Host field should be set to your SMTP
server (ex.
> mail.mycompany.com)<br>" );
> out.println( "<p><form action=/servlet/EmailServlet
method=POST><table>"
> );
> out.println( "<tr><td>Host :</td><td><input type=text
size=50
> name=\"host\"></td></tr>" );
> out.println( "<tr><td>From :</td><td><input type=text
size=50
> name=\"from\"></td></tr>" );
> out.println( "<tr><td>Subject :</td><td><input type=text
size=50
> name=\"subject\"></td></tr>" );
> out.println( "<tr><td>To :</td><td><input type=text
size=50
> name=\"to\"></td></tr>" );
> out.println( "<tr><td>To (optional):</td><td><input
type=text size=50
> name=\"to\"></td></tr>" );
> out.println( "<tr><td>Cc (optional):</td><td><input
type=text size=50
> name=\"cc\"></td></tr>" );
> out.println( "<tr><td>Cc (optional):</td><td><input
type=text size=50
> name=\"cc\"></td></tr>" );
> out.println( "<tr><td>Bcc (optional):</td><td><input
type=text size=50
> name=\"bcc\"></td></tr>" );
> out.println( "<tr><td>Bcc (optional):</td><td><input
type=text size=50
> name=\"bcc\"></td></tr>" );
> out.println( "</table>Message: <textarea name=\"message\"
rows=3 cols=48
> wrap></textarea>" );
> out.println( "<p><input type=Submit name=Submit
value=Submit>" );
> out.println( "</form></center></body></html>" );
> }
>
> // Sends the email message
> public void doPost( HttpServletRequest req, HttpServletResponse res )
> throws ServletException, IOException
> {
> int i;
>
> // Get the PrintWriter from the response object
> PrintWriter out = res.getWriter();
>
> // Retrieve the parameters from the HTML form
> String host =
req.getParameter( "host" );
> String from =
req.getParameter( "from" );
> String subject =
eq.getParameter( "subject" );
> String[] to =
req.getParameterValues( "to" );
> String[] cc =
req.getParameterValues( "cc" );
> String[] bcc =
eq.getParameterValues( "bcc" );
> String message =
eq.getParameter( "message" );
>
> if ( ( host == null ) || ( host.length() == 0 ) ||
> ( from == null ) || ( from.length() == 0 ) ||
> ( to == null ) || ( to.length == 0 ) ||
> ( subject == null ) || ( subject.length() == 0 ) ||
> ( message == null ) || ( message.length() == 0 ) )
> {
> out.println( "<html><head><title>Email
Servlet</title></head>" );
> out.println( "<body><center><h1>Email
Servlet</h1>" );
> out.println( "<b>You must enter a host, from, to,
subject and
> message.</b>" );
> out.println( "</center></body></html>" );
> return;
> }
>
> try
> {
> // Set the host
> Properties props = new Properties();
> props.put( "mail.host", host );
>
> // Get a Session object
> Session session = Session.getInstance( props, null );
> if ( debug ) session.setDebug( true );
>
> // Construct the message
> Message msg = new MimeMessage( session );
> msg.setFrom( new InternetAddress( from ) );
>
> for ( i = 0; i < to.length; i++ )
> {
> if ( to[ i ].length() > 0 )
>
sg.setRecipients( Message.RecipientType.TO, InternetAddress.parse(
> to[ i ], false ) );
> }
> if ( cc != null )
> {
> for ( i = 0; i < cc.length; i++ )
> {
> if ( cc[ i ].length() > 0 )
>
sg.setRecipients( Message.RecipientType.CC, InternetAddress.parse(
> cc[ i ], false ) );
> }
> }
> if ( bcc != null )
> {
> for ( i = 0; i < bcc.length; i++ )
> {
> if ( bcc[ i ].length() > 0 )
>
sg.setRecipients( Message.RecipientType.BCC, InternetAddress.parse(
> bcc[ i ], false ) );
> }
> }
>
> msg.setSubject( subject );
>
> msg.setText( message );
>
> msg.setHeader( "X-Mailer", "EmailServlet" );
> msg.setSentDate( new Date() );
>
> // Send the email message
> Transport.send( msg );
>
> out.println( "<html><head><title>Email
Servlet</title></head>" );
> out.println( "<body><center><h1>Email
Servlet</h1>" );
> out.println( "<b>The message has been
sent.</b>" );
> out.println( "</center></body></html>" );
> }
> catch ( Exception e )
> {
> out.println( "<html><head><title>Email
Servlet</title></head>" );
> out.println( "<body><center><h1>Email
Servlet</h1>" );
> out.println( "<b>Failed to send message.</b>" );
> out.println( "<p><pre>" + e + "</pre>" );
> out.println( "</center></body></html>" );
> }
> }
> }
> *******************************************************
>
> ______________________________________________________
> Get Your Private, Free Email at http://www.hotmail.com
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html