Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I am so glad that I found your site, it is an excellent resource and has helped me greatly..."

Geography

Where in the world do Tek-Tips members come from?
doreen (Instructor)
4 Mar 01 1:29
Hi Expertssss,
I got 2 error messages while compiling the java source code.
i.e.  

1)MailTest.java:6: Package javax.swing not found in import.
import javax.swing.*;

2)MailTest.java:15: Superclass JFrameof classMailTestFrame not found.
class MailTestFrame extends JFrame.

Pls see attached source code for more information.

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;

public class MailTest
{  public static void main(String[] args)
   {  JFrame frame = new MailTestFrame();
      frame.show();
   }
}

class MailTestFrame extends JFrame
   implements ActionListener
{  public MailTestFrame()
   {  setTitle("MailTest");
      setSize(300, 300);
      addWindowListener(new WindowAdapter()
         {  public void windowClosing(WindowEvent e)
            {  System.exit(0);
            }
         } );

      getContentPane().setLayout(new GridBagLayout());

      GridBagConstraints gbc = new GridBagConstraints();
      gbc.fill = GridBagConstraints.HORIZONTAL;
      gbc.weightx = 0;
      gbc.weighty = 0;

      gbc.weightx = 0;
      add(new JLabel("From:"), gbc, 0, 0, 1, 1);
      gbc.weightx = 100;
      from = new JTextField(20);
      add(from, gbc, 1, 0, 1, 1);

      gbc.weightx = 0;
      add(new JLabel("To:"), gbc, 0, 1, 1, 1);
      gbc.weightx = 100;
      to = new JTextField(20);
      add(to, gbc, 1, 1, 1, 1);

      gbc.weightx = 0;
      add(new JLabel("SMTP server:"), gbc, 0, 2, 1, 1);
      gbc.weightx = 100;
      smtpServer = new JTextField(20);
      add(smtpServer, gbc, 1, 2, 1, 1);

      gbc.fill = GridBagConstraints.BOTH;
      gbc.weighty = 100;
      message = new JTextArea();
      add(new JScrollPane(message), gbc, 0, 3, 2, 1);

      response = new JTextArea();
      add(new JScrollPane(response), gbc, 0, 4, 2, 1);

      gbc.weighty = 0;
      JButton sendButton = new JButton("Send");
      sendButton.addActionListener(this);
      JPanel buttonPanel = new JPanel();
      buttonPanel.add(sendButton);
      add(buttonPanel, gbc, 0, 5, 2, 1);
   }

   private void add(Component c, GridBagConstraints gbc,
      int x, int y, int w, int h)
   {  gbc.gridx = x;
      gbc.gridy = y;
      gbc.gridwidth = w;
      gbc.gridheight = h;
      getContentPane().add(c, gbc);
   }

   public void actionPerformed(ActionEvent evt)
   {  SwingUtilities.invokeLater(new Runnable()
        {  public void run()
           {   sendMail();
           }
        });
   }

   public void sendMail()
   {  try
      {  Socket s = new Socket(smtpServer.getText(), 25);

         out = new PrintWriter(s.getOutputStream());
         in = new BufferedReader(new
            InputStreamReader(s.getInputStream()));

         String hostName
            = InetAddress.getLocalHost().getHostName();

         send(null);
         send("HELO " + hostName);
         send("MAIL FROM: " + from.getText());
         send("RCPT TO: " + to.getText());
         send("DATA");
         out.println(message.getText());
         send(".");
         s.close();
      }
      catch (IOException exception)
      {  response.append("Error: " + exception);
      }
   }

   public void send(String s) throws IOException
   {  if (s != null)
      {  response.append(s + "\n");
         out.println(s);
         out.flush();
      }
      String line;
      if ((line = in.readLine()) != null)
         response.append(line + "\n");
   }

   private BufferedReader in;
   private PrintWriter out;
   private JTextField from;
   private JTextField to;
   private JTextField smtpServer;
   private JTextArea message;
   private JTextArea response;
}



rgds,
dor
jnicho02 (Programmer)
8 Mar 01 11:25
1. check that you are using Java 1.2 or above, if you have to stay with Java 1.1 you can download the extra javax.Swing package.

2. JFrame is in the javax.Swing package so wasn't found

My home ----> http://www.geocities.com/jnicho02/
My company -> http://www.firstlightassociates.co.uk/

doreen (Instructor)
9 Mar 01 3:41
Thx jnicho02....
I just download jdk1.2.2 and It works.. What code shoild i add to MailTest.java above in order me to check email n send attachment. Pls provide me the code so that i can learn from it.

Thx again,
doreen
jnicho02 (Programmer)
20 Mar 01 6:01
Not sure as yet about receiving mail, and sending attachments, but it is interesting.

Need to look at SMTP and MIME format, the JavaMail package would probably answer most of the problems, but it is in the doing that we learn, not in being told.

It is making me think about crossing Open Source with training courses and do a sort of mentor-guided software development. I don't claim to be an expert in all uses of Java, but could co-ordinate efforts.

My home ----> http://www.geocities.com/jnicho02/
My company -> http://www.firstlightassociates.co.uk/

jnicho02 (Programmer)
21 Mar 01 5:12
In fact, after checking it out a bit. The new JavaMail API is definitely the thing to use to create a mail program.

My home ----> http://www.geocities.com/jnicho02/
My company -> http://www.firstlightassociates.co.uk/

doreen (Instructor)
22 Mar 01 19:12

We need coding for JavaMail API??? I think we just specify smtp server n pop3 server??? am i right???
doreen (Instructor)
7 Apr 01 12:02
hi jnicho02,
thx for yr reply.. i did it using jdk1.2.2. but how am i add subject and also sending attachment. Pls help and add into my code above..

actually...i hv to use pure java instead of JavaMail.
thx n looking forward to hearing from u asap.

doreen
jnicho02 (Programmer)
26 Apr 01 12:10
Doreen,
       Take a look at John Zukowski's tutorial on jGuru

http://developer.java.sun.com/developer/onlineTraining/JavaMail

Even if you don't want to use the additional API it will give you some clues of how to go about writing a mail client. As a professional developer I see the use of extension APIs as being a core skill in knowing Java. Why would you want to re-invent the wheel?

My home ----> http://www.firstlightassociates.co.uk/
visit me for Java and Data Warehousing resources

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close