public Email(String smtp,String from,String to)
{
this.smtpServer=smtp;
this.fromMail=from;
this.toMail=to;
}
public void mail(String subject,String content) throws MailException
{
try{
//打开邮件服务器port:25
Socket s = new Socket(smtpServer,25);
//用于socket读写数据
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String res = null; //smtp服务器返回信息
out.println("HELO "+smtpServer);
res=in.readLine();
if( !res.startsWith("220") ) throw new MailException("MailException:"+res);
out.println("MAIL FROM: "+fromMail);
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);
out.println("RCPT TO: "+toMail);
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);
out.println("DATA");
res = in.readLine();
if( !res.startsWith("250") ) throw new MailException("MailException:"+res);