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

📄 sendmail.txt

📁 java编写的接受邮件程序
💻 TXT
字号:
import java.io. *;
import java.awt. *;
import java.net. *;
class sendmail extends Frame
{
PrintStream ps=null;
DataInputStream dis=null;
String strmailchs,strmailto,strsubject,strbody;
String strbodyend="\r\n. \r\n";
TextArea taletter,tastatus;
TextField tfmailto,tfchs,tfsubject;
Label lbmailto,lbchs,lbsubject,lbletter,lbstatus;
Button btceshi ,btsend,btattach,btchange;
Socket smtp=null;
public void send(String str) throws IOException
{
  ps.println(str);
  ps.flush();
tastatus.appendText("Java send:"+str+"\n");
}
public void receive() throws IOException
{
String readstr=dis.readLine();
tastatus.appendText("Java receive:"+readstr+"\n");
}
public static void main(String args[])
{
sendmail sm= new sendmail();
sm.show();
}
public sendmail()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
lbmailto=new Label("收件人");
tfchs=new TextField(155);
lbchs=new Label("抄送");
tfmailto=new TextField(155);
lbsubject=new Label("主题");
tfsubject=new TextField(155);
lbletter=new Label("信件内容");
lbstatus=new Label("发送邮件状态");
btsend=new Button ("发送");
btattach=new Button("附件");
btchange=new Button("切换帐户");
btceshi=new Button("测试");
tastatus=new TextArea (12,155);
tastatus.setEditable(true);
taletter=new TextArea (20,155);
taletter.setEditable(true);
add(btsend);
add(btchange);
add(btattach);
add(btceshi);
add (lbmailto);
add (tfmailto);
add (lbchs);
add (tfchs);
add(lbstatus);
add(tastatus);
add(lbsubject);
add(tfsubject);
add(lbletter);
add(taletter);
setTitle("发送电子邮件");
resize(1280,1000);
}
public boolean action(Event evt,Object obj)
{
if(evt.target==btsend)
{
tastatus.appendText("Now Start to send. \n");
try
{
String loc=InetAddress.getLocalHost().getHostName();
send("HELO"+loc);
receive();
send("MAIL FROM:"+"xgqx2008@sina.com.cn");
receive();
send("RECP TO:"+strmailto);
receive();
send("DATA");
receive();
send("SUBJECT"+strsubject);
receive();
send(strbody +strbodyend);
receive();
smtp.close();
}
catch(IOException e){tastatus.appendText("Error sending!\n");
}
tastatus.appendText("Send Comolete!\n");
}
else if (evt.target==btceshi)
{
tastatus.appendText("Now Start to connect.\n");
try
{
smtp=new Socket("smtp.sina.com.cn",25);
OutputStream os=smtp.getOutputStream();
ps=new PrintStream(os);
InputStream is=smtp.getInputStream();
dis=new DataInputStream(is);
tastatus.appendText("Connect complete!\n");
}
catch (IOException e) {tastatus.appendText("Error connceting!\n");
}
strmailchs=tfchs.getText();
strmailto=tfmailto.getText();
strsubject=tfsubject.getText();
strbody=taletter.getText();
}
return super.action(evt,obj);
}
public boolean handle(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 + -