Chinaunix首页 | 论坛 | 博客
  • 博客访问: 483703
  • 博文数量: 1496
  • 博客积分: 79800
  • 博客等级: 大将
  • 技术积分: 9940
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 13:22
文章分类

全部博文(1496)

文章存档

2011年(1)

2008年(1495)

我的朋友

分类:

2008-09-09 13:31:01


  import java.awt.*;
  
  import java.applet.*;
  
  import java.net.*;
  
  import java.io.*;
  
  public class mail extends Applet {
  
  private int SMTP_PORT = 25;
  
  //邮件缺省端口号
  
  private String appletSource = "202.99.96.140";
  
  //作者邮件IP
  
  private TextArea MsgArea;
  
  private TextField senderField, recipientField, hostField;
  
  public void init() {
  
  setLayout(new BorderLayout());
  
  Panel fields = new Panel();
  
  fields.setLayout(new GridLayout(3, 1));
  
  Panel recPanel = new Panel();
  
  recPanel.setLayout(new GridLayout(2, 1));
  
  recPanel.add(new Label("Recipient"));
  
  recipientField = new TextField("zffan");
  
  // 作 者 邮 件 服 务 器 用 户 名
  
  recPanel.add(recipientField);
  
  fields.add(recPanel);
  
  Panel sendPanel = new Panel();
  
  sendPanel.setLayout(new GridLayout(2, 1));
  
  sendPanel.add(new Label("Sender"));
  
  senderField = new TextField("Your Name");
  
  // 由 读 者 填 其 用 户 名
  
  sendPanel.add(senderField);
  
  fields.add(sendPanel);
  
  Panel hostPanel = new Panel();
  
  hostPanel.setLayout(new GridLayout(2, 1));
  
  hostPanel.add(new Label("Host"));
  
  hostField = new TextField("YourCompany.com");
  
  // 由 读 者 填 其 邮 件 服 务 器IP
  
  hostPanel.add(hostField);
  
  fields.add(hostPanel);
  
  add("North", fields);
  
  MsgArea = new TextArea();
  
  add("Center", MsgArea);
  
  add("South", new Button("SEND"));
  
  }
  
  public boolean handleEvent(Event e) {
  
  if (e.id == Event.WINDOW_DESTROY)
  
  System.exit(0);
  
  return super.handleEvent(e);
  
  }
  
  public boolean action(Event e, Object arg) {
  
  if (arg.equals("SEND"))
  
  sendMsg(senderField.getText(),
  
  recipientField.getText(), hostField.getText());
  
  else
  
  return super.action(e, arg);
  
  return true;
  
  }
  
  
  
  private void sendMsg(String sender, String recipient, String se
  
  
  
  nderHost) {
  
  try { // 与 邮 件 服 务 器 通 信
  
  Socket s = new Socket(appletSource, SMTP_PORT);
  
  PrintStream out = new PrintStream(s.getOutputStream());
  
  MsgArea.selectAll();
  
  out.println("HELO " + senderHost);
  
  //邮件服务器不认证读者所输SMTP是否正确
  
  out.println("MAIL FROM: " + sender);
  
  out.println("RCPT TO: " + recipient);
  
  out.println("DATA");
  
  out.println(MsgArea.getSelectedText());
  
  out.println(".");
  
  out.println("QUIT");
  
  }
  
  catch(Exception e) { System.out.println("Error " + e); }
  
  }
  
  } //mail
  
  
【责编:admin】

--------------------next---------------------

阅读(132) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~