//最近在教学JavaMail时采用的username/password认证代码,zfluynu
import javax.mail.*;
public class MailAuthenticator extends Authenticator...{
String authenName; //用户名
String authenPass; //密码
public MailAuthenticator(String authenName,String authenPass) ...{
super();
this.authenName=authenName;
this.authenPass=authenPass;
}
public PasswordAuthentication getPasswordAuthentication()...{
//若服务器需要身份认证,Session会自动调用这个方法
return new PasswordAuthentication(authenName,authenPass);
}
}