Article View: cn.bbs.comp.lang.java
Article #24274����Email��JAVAԴ����
From: wooce
Date: Fri, 27 Mar 1998 00:00
Date: Fri, 27 Mar 1998 00:00
89 lines
6451 bytes
6451 bytes
/** MailWin Version 0.1 by Aaron Conaway This version written 14-1-98 */
import java.io.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class mailwin extends Applet { private static Socket sock = null; private static String server = null; private static PrintWriter pw = null; private static TextField fromfield = new TextField(); private static TextField tofield = new
TextField(); private static TextField subfield = new TextField(); private static TextArea mesarea = new TextArea(); private static Button send = new Button("Send"); private static Button reset = new Button("Reset"); private static Button help = new
Button("Help"); private static String status = new String("Ready."); private static xframe x = new xframe("Help"); private static String to = new String(); private static String from = new String(); private static String sub = new String(); private
static String mes = new String(); public mailwin() { } // Sets up the applet window
public void init()
{ resize(500,500);
// The ususal setup stuff to get widgets straight setLayout(null); //addNotify(); // Make all the widgets look right. tofield.reshape(50,50,225,25); subfield.reshape(50,100,225,25); fromfield.reshape(50,75,225,25); mesarea.reshape(12,138,263,213);
send.reshape(25,375,63,25); reset.reshape(200,375,63,25); help.reshape(115,375,63,25); /*fromfield.setText("you"); tofield.setText("recipient"); subfield.setText("Enter the subject here."); mesarea.setText("Enter your message here."); */
add(fromfield); add(subfield); add(tofield); add(mesarea); add(send); add(reset); add(help); try { //server = getCodeBase().getHost(); server = "gsaix2.cc.gasou.edu"; } catch (Exception e) { System.err.println(e); status = "Couldn't get server
address"; repaint(); } } public void paint(Graphics g) { g.drawString("MailWin Version 0.1",0,0); g.drawString(status,12,425); g.drawString("To:",12,67); g.drawString("From:",12,93); g.drawString("Sub:",12,119); g.setFont(new
Font("Arial",Font.BOLD,22)); g.drawString("MailWin Version 0.1",12,30); }
public boolean action(Event ev, Object arg)
{ if(arg == "Send")
{ sendClicked(); return true; }
if(arg == "Reset") { resetClicked(); return true; }
if(arg == "Help") { helpClicked(); return true; }
return false;
}
public void sendClicked()
{ to = tofield.getText();
from = fromfield.getText();
sub = subfield.getText();
mes = mesarea.getText();
to = to.trim();
from = from.trim();
sub = sub.trim();
if (checkAddy(to) && checkAddy(from))
{ status = "Connecting to server.";
repaint();
sendMail();
}
}
public boolean checkAddy(String str)
{ if ((str.indexOf("@") > 1) && (str.indexOf("@") < str.length() - 1) && (str.indexOf("@") > 0) && (str.indexOf("@") == str.lastIndexOf("@"))) return true; else { status = str +": Invalid email address."; repaint(); return false; } } public
static void sendMail() { connect2server(); write2server(); disconnect(); }
/** METHOD: connect2server
This method opens the connection to the server and prepares to write. */
public static void connect2server()
{ try { sock = new Socket(server,25);
pw = new PrintWriter(sock.getOutputStream());
} catch (Exception e)
{ System.err.println("Couldn't connect");
errorOccurred(e); } } /** This method prints the data to the server for processing using SMPT protocol. */ public static void write2server() { try { pw.println("helo"); System.err.println("Printed helo"); pw.print("mail from:");
pw.println(from); System.err.println("Printed mail from"); pw.print("rcpt to:"); pw.println(to); System.err.println("Printed rcpt to"); pw.println("data"); pw.println("To: " + to); pw.println("From: " + from); pw.println("Subject: " + sub);
pw.println(mes); pw.println("."); System.err.println("Printed message"); status = "Done sending message."; // repaint(); } catch (Exception e) { System.err.println("Could not write to server."); } } /** This method disconnects from the server and
closes the socket. */ public static void disconnect() { try { pw.println("quit");
System.err.println("Quitting");
} catch (Exception e)
{ System.err.println("Could not disconnect from server."); } try { pw.close(); } catch (Exception e) { System.err.println("Could not disconnect from server."); } } public void resetClicked() { tofield.setText(""); fromfield.setText("");
subfield.setText(""); mesarea.setText(""); status = "Ready."; repaint(); } public String getAppletInfo() { return "MailApplet v. 0.1\nDeveloped January 1998\nAuthor: Aaron Conaway\nTools: JDK 1.2 Beta 2 and Ultra-Edit32"; } public void helpClicked() {
//("Help stuff here."); x = new xframe("help"); x.show(); }
public static void errorOccurred(Exception e)
{ String error = new String(e.toString()); status = error; //repaint(); } }
class xframe extends Frame { private TextArea ta;
private String text = new String("Help for MailWin v.0.1
1. 'To:' is the person to whom you want to send the email message.
2. 'From' is your email address.
3. 'Sub' is the subject which you would like to appear.n The large textarea is your message.
The Send button is for sending the message. Help brings up this \nwindow. Reset clears all fields.");
private Button ok = new Button("OK");
public xframe(String title)
{ setTitle("Help for MailWin Version 0.1");
setLayout(null);
resize(390,400);
ta = new TextArea(text);
ta.reshape(0,30,390,255);
ta.setEditable(false);
add(ta);
ok.reshape(150,295,63,25);
add(ok); }
public boolean action(Event ev, Object arg)
{ if (arg == "OK") { dispose(); return true; }
return super.handleEvent(ev);
}
}
--
[m[1;35m�� ��Դ:���������� BBS bbs.nease.net��[FROM: 202.96.174.34][m
Technical Details
Message-ID:
<3NeDlP$7il@bbs.nease.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f6cb0,3af649d08096041b,start X-Google-Attributes: gidf6cb0,public From: wooce.bbs@bbs.nease.net (wooce) Subject: ����Email��JAVAԴ���� Date: 1998/03/27 Message-ID: <3NeDlP$7il@bbs.nease.net> X-Deja-AN: 338095903 X-Filename: Java/M.890961385.A Organization: Net Ease Newsgroups: cn.bbs.comp.lang.java,