首先,写一个从Authenticator继承的类,如下:PassAuthenticator.java
-------------------------import javax.mail.*;
import java.util.*;public class PassAuthenticator extends Authenticator {
String sUserName = "";
String sPassword = "";
public PassAuthenticator(String prm_sUserName,
String prm_sPassword){
sUserName = prm_sUserName;
sPassword = prm_sPassword; }
public PasswordAuthentication getPasswordAuthentication(String prm_sUserName,
String prm_sPassword) {
return new PasswordAuthentication(sUserName, sPassword);
}
}然后,在创建mail session的时候,将这样的一个类作为实例化的参数: Authenticator auth = new PassAuthenticator(sUser, sPass);
Session session = Session.getInstance(props, auth);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货