//最近在教學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);
}
}