SMTP协议,返回正确,但为什么收不到邮件呢?
import java.io.*;
import java.net.*;
class sendmail
{
public static void main(String args[])throws Exception
{
String ip;
String sstr;
String from=new String("From: <");
String to=new String("To: ");
byte[] r=new byte[500];
int num;
Socket s=new Socket("smtp.163.com",25);
ip=s.getLocalAddress().toString();
ip=ip.substring(1);
System.out.println("本地IP:"+ip);
DataInputStream in=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String lin;
lin=in.readLine();
System.out.println(lin);
if(lin.indexOf("220")==-1)
{System.out.println("连接服务器错误");System.exit(0);}
System.out.println("连接成功");//接收连接是返回信息
sstr=new String("EHLO ");
System.out.println("要连接的服务器:");
num=System.in.read(r);
sstr+=new String(r,0,num);
out.write(sstr.getBytes());
out.flush();//发送HELO
lin=in.readLine();
System.out.println("发送:"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("邮件会话失败");System.exit(0);}
sstr=new String("MAIL FROM:<");
System.out.println("发件人:");
num=System.in.read(r);
from+=new String(r,0,num-2)+">\r\n";
sstr+=new String(r,0,num-2)+">\r\n";
out.write(sstr.getBytes());
out.flush();//发送mail from
lin=in.readLine();
System.out.println("发送:"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("发件人地址错误");System.exit(0);}
sstr=new String("RCPT TO:");
System.out.println("收件人:");
num=System.in.read(r);
to+=new String(r,0,num);
sstr+=new String(r,0,num-2)+">\r\n";
out.write(sstr.getBytes());
out.flush();//发送rcpt to
lin=in.readLine();
System.out.println("发送:"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("收件人地址错误");System.exit(0);}
sstr=new String("DATA\r\n");
out.write(sstr.getBytes());
out.flush();
lin=in.readLine();
System.out.println("发送:"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("邮件内容传输失败");System.exit(0);}
sstr=new String("Subject: ");
System.out.println("主题:");
num=System.in.read(r);
sstr+=new String(r,0,num);
sstr+=from;
sstr+=to;
System.out.println("内容:");
num=System.in.read(r);
sstr+=new String(r,0,num);
sstr+="\r\n.\r\n";
out.write(sstr.getBytes());
out.flush();
lin=in.readLine();
System.out.println("发送邮件:\r\n"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("发送邮件失败");System.exit(0);}
System.out.println("发送成功");
sstr=new String("QUIT");
out.write(sstr.getBytes());
out.flush();
System.out.println("发送离开信息:"+sstr+"返回:"+lin);
if(lin.indexOf("250")==-1)
{System.out.println("关闭失败");System.exit(0);}
s.close();
}//main
}//class
/*
输入下面的:
smtp.163.com
user1@163.com
user2@163.com
标题 你好
内容 收到了吗?
返回的值是250,表示对了的噻.
但为什么我在WEB邮箱中找不到邮件.
用POP3也找不邮件.
这是为什么呢????
*/