//用户认证类
package cn.mail;import javax.mail.PasswordAuthentication;public class EmailAuthenticator extends javax.mail.Authenticator {
public EmailAuthenticator(String username,String password) {
setUsername(username);
setPassword(password);
}
private String username;
private String password;
public void setUsername(String username)
{
this.username = username;
}
public void setPassword(String password)
{
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username,password);
}
}
使用例子Properties props = new Properties();
props.put("mail.smtp.host", accountValue.sendServer);
props.put("mail.smtp.auth","true");
Authenticator authenticator = new EmailAuthenticator(
accountValue.username,accountValue.password);
mailSession = Session.getInstance(props, authenticator);
store = mailSession.getStore(accountValue.receiveServerType);
store.connect(accountValue.receiveServer, accountValue.username,
accountValue.password);登陆即可~
package cn.mail;import javax.mail.PasswordAuthentication;public class EmailAuthenticator extends javax.mail.Authenticator {
public EmailAuthenticator(String username,String password) {
setUsername(username);
setPassword(password);
}
private String username;
private String password;
public void setUsername(String username)
{
this.username = username;
}
public void setPassword(String password)
{
this.password = password;
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username,password);
}
}
使用例子Properties props = new Properties();
props.put("mail.smtp.host", accountValue.sendServer);
props.put("mail.smtp.auth","true");
Authenticator authenticator = new EmailAuthenticator(
accountValue.username,accountValue.password);
mailSession = Session.getInstance(props, authenticator);
store = mailSession.getStore(accountValue.receiveServerType);
store.connect(accountValue.receiveServer, accountValue.username,
accountValue.password);登陆即可~
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货