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

我想请问各位大侠为什么下面的这个发邮件的程序只有用 sina 的用户好使,别的都不好用呢?
//发邮件类
package emai;
import java.io.*;  
import java.util.*;  
import java.util.Date;  
import javax.activation.DataHandler;  
import javax.mail.*;  
import javax.mail.internet.*;  
public class Mail {
public boolean sendMail(String subject,String body,String to){  
  try {  
  SmtpAuth sa=new SmtpAuth(); //密码验证  
  sa.getuserinfo("hhhsir","xxxxxxxx");  
  Properties props=System.getProperties();  
  props.put("mail.smtp.auth","true");  
  props.put("mail.smtp.host","smtp.sina.com");  
  Session sess=Session.getInstance(props,sa);  
  sess.setDebug(true);//调试信息  
  Message msg = new MimeMessage(sess);  
  msg.setDataHandler(new DataHandler(body,"text/html; charset=gb2312"));  
  msg.setFrom(new InternetAddress("hhhsir@sina.com",true));  
  msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));  
  msg.setSubject(subject);  
  msg.setSentDate(new Date());  
  msg.setText(body);  
  Transport.send(msg);  
  return true;  
  } catch (Exception e) {  
  return false;  
  }  
}  

public static void main(String[] args){  
Mail m=new Mail();  
m.sendMail("test","JAVA456API","hhhsir@126.com");  
}  
}  
//密码验证类
public class SmtpAuth extends javax.mail.Authenticator{

private String user,password;  
  public void getuserinfo(String getuser,String getpassword){  
  user=getuser;  
  password=getpassword;  
  }  

  protected javax.mail.PasswordAuthentication getPasswordAuthentication(){  
  return new javax.mail.PasswordAuthentication(user,password);  
  }  


}

还请各位大侠帮忙册一下

------解决方案--------------------
邮件服务器发送需要验证的
------解决方案--------------------
有些不是程序问题,163,126邮箱有新规定,新申请的邮箱暂时不能用客户端软件收发邮件,只能用web方式,据说交了钱就行了