日期:2014-05-20  浏览次数:20856 次

一个发送e-mail的程序,有点问题,大家帮忙看看
rt!
程序如下:
import   java.net.*;
import   java.io.*;

public   class   SendMail  
{
static   PrintStream   ps=null;
static   DataInputStream   dis=null;

public   static   void   send(String   str) throws   IOException
{
ps.println(str);
ps.flush();
System.out.println( "local   send: "+str);
}

public   static   void   receive()   throws   IOException
{
String   readStr=dis.readLine();
System.out.println( "STMP   respose: "+readStr);
}

public   static   void   main(String[]   args)
{
String   HELO= "HELO ";
                String   MAIL_FROM= "MAIL_FROM:   he.wenhao@163.com ";
                String   RECP_TO= "RCPT_TO:   he.wenhao@163.com ";
                String   SUBJECT= "SUBJECT:Java   is   cool! ";
                String   DATA= "DATA ";
                String   BODY= "Java   send   this!\r\n.\r\n ";
                Socket   smtp=null;  
               
                try
                {
                smtp=new   Socket( "smtp.163.com ",25);
                OutputStream   os=smtp.getOutputStream();
                ps=new   PrintStream(os);
                InputStream   is=smtp.getInputStream();
                dis=new   DataInputStream(is);
               
                }
                catch(IOException   e)
                {
                System.out.println(e);
                }
               
                try
                {                        
                String   loc=InetAddress.getLocalHost().getHostName();
                        send(HELO+loc);
                        receive();   //得到smtp响应
                        send(MAIL_FROM);   //从地址发出
                        receive();   //得到smtp响应
                        send(RECP_TO);   //发送smtp给谁
                        receive();   //得到smtp响应