⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 receivemail.txt

📁 java编写的接受邮件程序
💻 TXT
字号:

import java.io.*;
import java.awt.*;
import java.net.*;
class receivemail extends Frame
{
PrintStream ps=null;
DataInputStream dis=null;
TextArea tastatus;
Button btini,btreceive;
Socket pop=null;
String strtest;
public void send (String str) throws IOException
{
  ps.println(str);
  ps.flush();
tastatus.appendText("Java send:"+str+"\n");
}
public void receive() throws IOException
{
while((strtest=dis.readLine())!=null)
tastatus.appendText("Java receive:"+strtest+"\n");
}
public static void main(String args[])
{
receivemail rm=new receivemail();
rm.show();
}
public receivemail()
{
tastatus=new TextArea(30,50);
btreceive=new Button("Receive!");
btini=new Button("Initial");
setLayout(new FlowLayout());
add(btreceive);
add(btini);
add(tastatus);
setTitle("接收电子邮件");
resize(600,600);
}
public boolean action(Event evt,Object obj)
{
if(evt.target==btreceive)
{
tastatus.appendText("Now Start to receive.\n");
try
{
send("USER"+"用户名");
receive();
send("PASS"+"密码");
receive();
send("STAT");
receive();
send("LIST");
receive();
send("RETR 1");
receive();
send("DELE 1");
receive();
send("QUIT");
receive();
pop.close();
}
catch(IOException e)
{
tastatus.appendText("Error sending!\n");
}
tastatus.appendText("Send Comolete!\n");
}
else if(evt.target==btini)
{
tastatus.appendText("Now Start to connect.\n");
try
{
pop=new Socket("sina.com",110);
OutputStream os=pop.getOutputStream();
ps=new PrintStream(os);
InputStream is=pop.getInputStream();
dis=new DataInputStream(is);
tastatus.appendText("Connect complete!\n");
}
catch (IOException e)
{
tastatus.appendText("Error connecting!\n");
}
}
return super.action(evt,obj);
}
public boolean handleEvent(Event e)
{
if(e.id==Event.WINDOW_DESTROY)
{
System.exit(0);
}
return super.handleEvent(e);
}
} 


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -